Class: Locomotive::Steam::Models::BelongsToAssociation

Inherits:
ReferencedAssociation show all
Defined in:
lib/locomotive/steam/models/associations/belongs_to.rb

Instance Attribute Summary

Attributes inherited from ReferencedAssociation

#repository

Instance Method Summary collapse

Methods inherited from ReferencedAssociation

#__attach__, #__call_block_once__, #__name__, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Locomotive::Steam::Models::ReferencedAssociation

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Locomotive::Steam::Models::ReferencedAssociation

Instance Method Details

#__load__Object



6
7
8
9
10
11
12
# File 'lib/locomotive/steam/models/associations/belongs_to.rb', line 6

def __load__
  target_id = @entity[__target_key__]
  target    = @repository.find(target_id)

  # replace the proxy class by the real target entity
  @entity[__name__] = target
end

#__serialize__(attributes) ⇒ Object



14
15
16
17
18
# File 'lib/locomotive/steam/models/associations/belongs_to.rb', line 14

def __serialize__(attributes)
  attributes[__target_key__] = attributes[__name__].try(:_id)

  attributes.delete(__name__)
end

#__target_key__Object



20
21
22
# File 'lib/locomotive/steam/models/associations/belongs_to.rb', line 20

def __target_key__
  :"#{__name__}_id"
end