Class: ActiveRecord::Associations::BelongsToAssociation

Inherits:
SingularAssociation show all
Defined in:
activerecord/lib/active_record/associations/belongs_to_association.rb

Overview

:nodoc:

Direct Known Subclasses

BelongsToPolymorphicAssociation

Instance Attribute Summary

Attributes inherited from Association

#owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from SingularAssociation

#build, #create, #create!, #reader, #writer

Methods inherited from Association

#aliased_table_name, #association_scope, #initialize, #interpolate, #klass, #load_target, #loaded!, #loaded?, #reload, #reset, #reset_scope, #scoped, #set_inverse_instance, #stale_target?, #target_scope

Constructor Details

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

Instance Method Details

#replace(record) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'activerecord/lib/active_record/associations/belongs_to_association.rb', line 5

def replace(record)
  raise_on_type_mismatch(record) if record

  update_counters(record)
  replace_keys(record)
  set_inverse_instance(record)

  @updated = true if record

  self.target = record
end

#updated?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'activerecord/lib/active_record/associations/belongs_to_association.rb', line 17

def updated?
  @updated
end