Can some one please explain the the pros and cons between has_many :through and has_and_belongs_to_many?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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).