Try This:
class Company < ActiveRecord::Base
belongs_to :business, :polymorphic => true
has_many :people
has_and_belongs_to_many :mops
end
class Person < ActiveRecord::Base
belongs_to :contactable, :polymorphic => true
belongs_to :company
end
class Contractorcompany < Company
end
class Contactcompany < Company
end
USE Inheritance... Not sure if I got the syntax correct but I think you get
the idea...
________________________
Steve Shepherd
Mob:+64 (0) 27 4338154
Email: sargshep-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Analyst
On Sat, May 2, 2009 at 4:51 AM, Me
<chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> I have 2 polymorphic models that I am trying to relate to each other:
>
> class Company < ActiveRecord::Base
> belongs_to :business, :polymorphic => true
> has_many :people
> has_and_belongs_to_many :mops
> end
>
> class Person < ActiveRecord::Base
> belongs_to :contactable, :polymorphic => true
> belongs_to :company
> end
>
> class Contractorcompany < ActiveRecord::Base
> has_one :company, :as => :business, :dependent
> => :destroy, :foreign_key => :business_id
> end
>
> class Contactcompany < ActiveRecord::Base
> has_one :company, :as => :business, :dependent
> => :destroy, :foreign_key => :business_id
> end
>
>
>
> The problem is that when I select a person according to
> contactable_type and then pull the company name I get hte company in
> the wrong table. Is there a way to make it so I do this:
>
> @contractor = Contractor.find(params[:contractorid])
> @company=Person.find_by_contactable_id_and_contactable_type
> (@contractor.id,''Contractor'').company.business.name
>
> It will pull from the contractorcompany table and not the
> contactcompany table?
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---