class ActiveRecord::Associations::BelongsToPolymorphicAssociation
:nodoc:
= Active Record Belongs To Polymorphic Association
def inverse_reflection_for(record)
def inverse_reflection_for(record) reflection.polymorphic_inverse_of(record.class) end
def klass
= Active Record Belongs To Polymorphic Association
def klass type = owner[reflection.foreign_type] type.presence && owner.class.polymorphic_class_for(type) end
def raise_on_type_mismatch!(record)
def raise_on_type_mismatch!(record) # A polymorphic association cannot have a type mismatch, by definition end
def replace_keys(record, force: false)
def replace_keys(record, force: false) super target_type = record ? record.class.polymorphic_name : nil if force || owner._read_attribute(reflection.foreign_type) != target_type owner[reflection.foreign_type] = target_type end end
def saved_change_to_target?
def saved_change_to_target? super || owner.saved_change_to_attribute?(reflection.foreign_type) end
def stale_state
def stale_state foreign_key = super foreign_key && [foreign_key.to_s, owner[reflection.foreign_type].to_s] end
def target_changed?
def target_changed? super || owner.attribute_changed?(reflection.foreign_type) end
def target_previously_changed?
def target_previously_changed? super || owner.attribute_previously_changed?(reflection.foreign_type) end