Class: Locomotive::Steam::Models::BelongsToAssociation
Instance Attribute Summary
#repository
Instance Method Summary
collapse
#__call_block_once__, #__name__, #initialize, #method_missing
Instance Method Details
#__attach__(entity) ⇒ Object
24
25
26
27
28
|
# File 'lib/locomotive/steam/models/associations/belongs_to.rb', line 24
def __attach__(entity)
entity[__target_key__] ||= nil
super
end
|
#__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)
@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
|