What is the convention when relevant data needs to be stored in a join table?
Suppose you have a data model that is something like
class Question
has_and_belongs_to_many :choices
end
Now suppose, on that choices model, there is a position column.开发者_C百科 What is the best way to access that information without having horrible messy queries / models?
The beauty of has_and_belongs_to_many is that it keeps things concise and simple. Is there a way to accomplish that, but still have access to my questions_choices
.position?
"You should use has_many :through
if you need validations, callbacks, or extra attributes on the join model."
- A Guide to Active Record Associations
精彩评论