On Mon, Nov 7, 2011 at 13:26, Mauro <mrsan...@gmail.com> wrote: > For example: I have a Company with many legal_representatives and a > LegaRepresentative that has many companies. > In this case you use a has_and_belongs_to_many or has_many :through? > What's reasoning that leads me to select has_and_belongs_to_many > rather than has_many :through?
The usual reason for using has_many :through (hmt) is that you need to attach some information to that relationship. For instance, you may want to record exactly *when* a given Legal_representative started representing a given Company, how much they're charging, etc. If you are absolutely sure you don't, and *never will*, need to attach any info to the relationship, then has_and_belongs_to_many (habtm) will do fine. BUT: First, but I've heard some people complain about difficulty getting that working (I haven't, and don't know what they were doing wrong), and secondly, if you're wrong, I've heard that it's very difficult to retrofit an existing habtm setup to become hmt (haven't tried to do that myself). So, aside from declaring one more class, there's no reason not to use hmt from the start. -Dave -- LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages. Where: Northern Virginia, Washington DC (near Orange Line), and remote work. See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence). Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.