views:

56

answers:

1

Can some one please explain the the pros and cons between has_many :through and has_and_belongs_to_many?

+5  A: 

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).

Milan Novota