[英]is using has_and_belongs_to_many for models is a bad idea?
有人可以解释一下has_many:through和has_and_belongs_to_many之间的利弊吗?
There is nothing bad about using habtm per se. 使用habtm本身没有什么不好。 The reason why many people don't use this kind of association is that they use has_many :through instead.
许多人不使用这种关联的原因是,他们使用has_many:through代替。 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).
尽管HABTM“隐藏”了中间表,但在使用has_many时:通过中间人本身就是一种资源-这通常是一件好事(如果没有用,您可以为关系加盖时间戳)。 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).
当您需要为这种关系添加一些行为或属性时(会以面向资源的方式设计系统时),您会遇到很多情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.