Class: ActiveFedora::Associations::BelongsToAssociation

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

Overview

:nodoc:

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

#association_scope, #initialize, #initialize_attributes, #load_target, #loaded!, #loaded?, #reload, #reset_scope, #scope, #set_inverse_instance, #stale_target?, #target_scope

Constructor Details

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

Instance Method Details

#decrement_countersObject

:nodoc:



32
33
34
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 32

def decrement_counters # :nodoc:
  # noop
end

#handle_dependencyObject



4
5
6
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 4

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

#increment_countersObject

:nodoc:



36
37
38
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 36

def increment_counters # :nodoc:
  # noop
end

#replace(record) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 8

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

  self.target = record
end

#resetObject



23
24
25
26
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 23

def reset
  super
  @updated = false
end

#updated?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 28

def updated?
  @updated
end