If you have these classes:
class Foo < ActiveRecord::Base
has_many :things, as: :content
end
class Bar < Foo
end
class Thing < ActiveRecord::Base
belongs_to :content, polymorphic: true
end
Then assigning a Bar
to thing.content
then Rail sets thing.content_type
to 'Foo'
.
>> thing = Thing.new
>> bar = Bar.new
>> thing.content = bar
>> thing.content_type
=> "Foo"
Can you make Rails use the actual type of a polymorphic object as the type
key, rather than the type of the object's superclass?
What happens if you redefine the
has_many
onBar
? Not ideal, but I wonder if it even works.