On Nov 7, 2011, at 1:26 PM, Mauro wrote:

> On 7 November 2011 13:43, Colin Law <clan...@googlemail.com> wrote:
>> On 7 November 2011 12:15, Mauro <mrsan...@gmail.com> wrote:
>>> I always has doubts on using has_and_belongs_to_many rather than
>>> has_many :through association.
>>> I have a model like this:
>>> 
>>> class Company < ActiveRecord::Base
>>>  has_many :categories
>>>  has_many :legal_representatives
>>>  has_many :tenders
>>>  has_many :documents
>>> end
>>> 
>>> I don't see any way to use another model for these associations, do
>>> you think it's better to use has_many :through anyway?
>> 
>> I don't understand what you are asking, you do not appear to be using
>> habtm or has many through.  Perhaps you can clarify the question
>> further
> 
> 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?

You choose has_many :through when you need to "decorate" the junction between 
the two models. Let's say that you needed to capture the date that a particular 
legal representative entered into an agreement with a company. You can't 
capture that in the strict habtm relationship -- that's just a "dumb" join 
table and can only store the fact that the relationship exists.

Walter

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

Reply via email to