开发者

is using has_and_belongs_to_many for models is a bad idea?

Can some one please explain the the pros and cons between has_many :through开发者_Go百科 and has_and_belongs_to_many?


There is nothing bad about using habtm per se. The reason why many people don't use this kind of association is that they use has_many :through instead. Why? Because it's more versatile. While HABTM "hides" the intermediary table, when using has_many :through the middle man is a resource by itself - which is usually a good thing (if for nothing, you can timestamp the relationship). You'll come across many situations when you'll need to add some behavior or attributes to such a relationship (when designing a system in a resource-oriented fashion).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜