Question

i am fairly new to rails and want to take advantage of the associations ActiveRecord provides in trying to set up a new project and schema. i have two models, users and questions. when a user is being set up by an administrative user, i have a form with checkboxes for a list of categories. i want these categories to map to specific questions to ask the setup user at a later time. my thinking is i have a mapping table, user_to_categories, that will allow me to get from the user to the necessary questions. but the questions table will have a primary key of question_id, so the has_many :through does not seem to work here. since many questions can be in the same category, category_id will just be another column in the questions table. any suggestions on how to set this up to take advantage of rails and active record associations?

Was it helpful?

Solution

Many to Many between user and categories and question belongs to category. Now when you add user select categories by passing category_ids through UI,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top