开发者

which is the better way to do many-to-many association?

开发者 https://www.devze.com 2023-01-29 05:26 出处:网络
Hey, everyone, in my last question link, In the answer which is given by Trip, he said: But that join table in Rails does not

Hey, everyone, in my last question link, In the answer which is given by Trip, he said:

But that join table in Rails does not have to be开发者_运维问答 created in a migration. It can be done exclusively in the models.

should I use a join table like my code or without join table by using :though? Which is the right way to go?


It depends on the requirement. See, primarily you should go with has_and_belongs_to_many as it does not need an extra model.

But if you need any other extra information to be saved in the table also along with association, then you must go with has_many :through option

0

精彩评论

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