Reputation: 3213
The documentation for inheritance explains how to easily implement STI given that you can choose the values for the type
column.
However, I have a legacy DB, and these values already exist. Let's say those are PRIORITY
, ECONOMY
, and FLEXI
, how do I specify how to map these values to subclasses?
class PriorityPassenger < Passenger
# map to PRIORITY
end
Upvotes: 0
Views: 217
Reputation: 121000
This should work (untested):
ActiveRecord::Inheritance::ClassMethods.prepend(Module.new do
def find_sti_class(type_name)
case type_name
when 'PRIORITY' then PriorityPassenger
...
else super(type_name)
end
end
end)
Upvotes: 1