ruby on rails - ActiveRecord many_to_many association confusion -


i creating quiz in rails , drawing blank on associations.

i have 3 tables know going there.

users    |___id    |___name  quizzes    |___id    |___user_id  questions    |___id    |___question    |___poss_answer_one    |___poss_answer_two    |___poss_answer_three    |___answer    |___test_version 

this started with. functionality of site follows:

a user can select questions 3 categories add active quiz (quizzes). user have 1 quiz @ time because when finish or restart new one, entry quizzes table re-created.

so user has_one quiz , quizzes belongs_to users.

next assuming quiz has_many questions , because questions re-usable , can included in many different quizzes, require join table?

if

quiz_questions    |___id    |___question_id    |___quiz_id 

in case require has_many through.

once done know how model associations, confusing myself because of wording.

probably need habtm association (see railscasts)

class quiz < activerecord::base   has_and_belongs_to_many :questions end 

Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -