Class: ActiveRecord::Associations::BelongsToPolymorphicAssociation

Inherits:
BelongsToAssociation show all
Defined in:
activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb

Overview

Active Record Belongs To Polymorphic Association

Instance Attribute Summary

Attributes inherited from Association

#disable_joins, #owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from BelongsToAssociation

#decrement_counters, #decrement_counters_before_last_save, #default, #handle_dependency, #increment_counters, #inversed_from, #reset, #updated?

Methods inherited from SingularAssociation

#build, #force_reload_reader, #reader, #writer

Methods inherited from Association

#create, #create!, #extensions, #initialize, #initialize_attributes, #inversed_from, #inversed_from_queries, #load_target, #loaded!, #loaded?, #marshal_dump, #marshal_load, #reload, #remove_inverse_instance, #reset, #reset_negative_cache, #reset_scope, #scope, #set_inverse_instance, #set_inverse_instance_from_queries, #stale_target?

Constructor Details

This class inherits a constructor from ActiveRecord::Associations::Association

Instance Method Details

#klassObject

:nodoc:



7
8
9
10
# File 'activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb', line 7

def klass
  type = owner[reflection.foreign_type]
  type.presence && owner.class.polymorphic_class_for(type)
end

#saved_change_to_target?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb', line 20

def saved_change_to_target?
  super || owner.saved_change_to_attribute?(reflection.foreign_type)
end

#target_changed?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb', line 12

def target_changed?
  super || owner.attribute_changed?(reflection.foreign_type)
end

#target_previously_changed?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb', line 16

def target_previously_changed?
  super || owner.attribute_previously_changed?(reflection.foreign_type)
end