On Tue, Jul 28, 2009 at 6:25 PM, Paul
Graham<[email protected]> wrote:
> class Company < ActiveRecord::Base
>
>  has_many :clients, :class_name => 'Company'
>  has_many :suppliers, :class_name => 'Company'
>
> end
>
> I have two tables set up called company_clients and company_suppliers
> that each contain company_id and either client_id or supplier_id.

has_many (along with a belongs_to in the other class) if for a 1-n
relation, but you are modelling an n-m relation.

class Company < ActiveRecord::Base
   has_and_belongs_to_many :clients, :class_name => "Company",
:join_table => :company_clients
   has_and_belongs_to_many :suppliers, :class_name => "Company",
:join_table => :company_suppliers
end

I'm  not entirely sure that this works, but it's more likely to.

-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to