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?