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

#inversed, #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, #initialize_attributes, #interpolate, #klass, #load_target, #loaded!, #loaded?, #marshal_dump, #marshal_load, #reload, #reset_scope, #scope, #set_inverse_instance, #stale_target?, #target_scope

Constructor Details

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

Instance Method Details

#decrement_countersObject

:nodoc:



34
35
36
# File 'activerecord/lib/active_record/associations/belongs_to_association.rb', line 34

def decrement_counters # :nodoc:
  with_cache_name { |name| decrement_counter name }
end

#handle_dependencyObject



6
7
8
# File 'activerecord/lib/active_record/associations/belongs_to_association.rb', line 6

def handle_dependency
  target.send(options[:dependent]) if load_target
end

#increment_countersObject

:nodoc:



38
39
40
# File 'activerecord/lib/active_record/associations/belongs_to_association.rb', line 38

def increment_counters # :nodoc:
  with_cache_name { |name| increment_counter name }
end

#replace(record) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'activerecord/lib/active_record/associations/belongs_to_association.rb', line 10

def replace(record)
  if record
    raise_on_type_mismatch!(record)
    update_counters(record)
    replace_keys(record)
    set_inverse_instance(record)
    @updated = true
  else
    decrement_counters
    remove_keys
  end

  self.target = record
end

#resetObject



25
26
27
28
# File 'activerecord/lib/active_record/associations/belongs_to_association.rb', line 25

def reset
  super
  @updated = false
end

#updated?Boolean



30
31
32
# File 'activerecord/lib/active_record/associations/belongs_to_association.rb', line 30

def updated?
  @updated
end