class Link < ActiveRecord::Base
include PolymorphicIntegerType::Extensions
belongs_to :source, polymorphic: true, integer_type: true
belongs_to :target, polymorphic: true, integer_type: true
def source=(val)
super(val)
end
def source_type=(val)
super(val)
end
end
the source= will override the method defined by the belongs_to and what will end up happening is that the source_type will not end up being created properly.
By created an anonymous module, we can prepend it to the class and then the super behaviour will work as expected.
Prior to this, if we have something like
the
source=
will override the method defined by thebelongs_to
and what will end up happening is that thesource_type
will not end up being created properly.By created an anonymous module, we can prepend it to the class and then the
super
behaviour will work as expected.