开发者

What is the convention when relevant data needs to be stored in a join table?

开发者 https://www.devze.com 2022-12-17 08:28 出处:网络
Suppose you have a data model that is something like class Question has_and_belongs_to_many :choices end

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号