I am trying to integrate with a Legacy table that has a column named "type".
Rails will "smartly" assume that whenever we have a 'type' column in a table, then it will try to use Single Table Inheritance.
Is there anyway to avoid this?
(I can't rename the column).
Well, most of the type it really is smart - convention over configuration has some very real benefits. ;-)
Where convention doesn't work, as in your case, there is (probably - at least, I've always found one so far...) a way around it. For legacy schemas there are a couple of possibilities that spring immediately to mind.
:type
as the STI indicator using set_inheritance_column
, thusclass LegacyValue < ActiveRecord::Base
set_inheritance_column 'does_not_have_one'
end
In Rails 4 set_inheritance_column is deprecated and self.inheritance_column should be used instead:
class LegacyValue < ActiveRecord::Base
self.inheritance_column = 'does_not_have_one'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With