Class: ActiveFedora::Associations::BelongsToAssociation

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

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from AssociationProxy

#initialize, #loaded, #loaded?, #reload, #reset, #target, #target=

Constructor Details

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

Dynamic Method Handling

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

Instance Method Details

#build(attributes = {}) ⇒ Object



9
10
11
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 9

def build(attributes = {})
  replace(@reflection.build_association(attributes))
end

#create(attributes = {}) ⇒ Object



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

def create(attributes = {})
  replace(@reflection.create_association(attributes))
end

#replace(record) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 13

def replace(record)
  if record.nil?
    remove_matching_property_relationship
  else
    raise_on_type_mismatch(record)

    remove_matching_property_relationship

    @target = (AssociationProxy === record ? record.target : record)
    @owner.add_relationship(@reflection.options[:property], record) unless record.new_record?
    @updated = true
  end

  loaded
  record
end