I have the following models:
class Installation < ActiveRecord::Base
belongs_to :original_lead, class_name: 'Lead'
end
class Lead < ActiveRecord::Base
has_many :originated_installations, as: :original_lead, class_name: 'Installation'
end
Lead uses STI, having a type column.
That means I want each lead to have multiple installations.
The problem is when I try to do something like:
Lead.first.installations
It raises an error
PG::UndefinedColumn: ERROR: column installations.original_lead_type
does not exist LINE 1: ...WHERE "installations"."original_lead_id" = $1 AND
"installations"."original_lead_type" = $2
So, it is looking for a lead with a specific type, but I don't care about the lead type.
I was able to workaround that by replacing the has_many statement on the Lead model as follows:
has_many :originated_installations, inverse_of: :original_lead,
foreign_key: :original_lead_id, class_name: 'Installation'
So, yes, my problem is solved, I just wanted to share and know if there is some other option I could have used instead.
