Class: ActiveRecord::Associations::BelongsToPolymorphicAssociation

Inherits:
AssociationProxy
  • Object
show all
Defined in:
lib/active_record/associations/belongs_to_polymorphic_association.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from AssociationProxy

#reflection

Instance Method Summary collapse

Methods inherited from AssociationProxy

#===, #aliased_table_name, #conditions, #initialize, #loaded, #loaded?, #proxy_owner, #proxy_reflection, #proxy_respond_to?, #proxy_target, #reload, #reset, #respond_to?, #target, #target=

Constructor Details

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveRecord::Associations::AssociationProxy

Instance Method Details

#replace(record) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/active_record/associations/belongs_to_polymorphic_association.rb', line 4

def replace(record)
  if record.nil?
    @target = @owner[@reflection.primary_key_name] = @owner[@reflection.options[:foreign_type]] = nil
  else
    @target = (AssociationProxy === record ? record.target : record)

    unless record.new_record?
      @owner[@reflection.primary_key_name] = record.id
      @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s
    end

    @updated = true
  end

  loaded
  record
end

#updated?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/active_record/associations/belongs_to_polymorphic_association.rb', line 22

def updated?
  @updated
end