开发者

When making model1_model2 tables, do I create a model or?

I have a users table, and a roles table.

I want to make a table like:

model1_model2

with columns:

model1_id
model2_id
other_column int
other_column2 int

S开发者_如何学Cince I need to expose those other columns (other than id's), do I just make a model that matches this table and call it Module1Module2?


It looks like you're looking for the has_and_belongs_to_many relationship.

You shouldn't be putting information in a join table unless it describes the relationship between the two models, in which case has_and_belongs_to_many does not apply and you must make a model specifically for the relation.


Pretty much.. This is an excelent resource with exactly what you're looking for: http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜