Method: ReactiveRecord::Base#update_mapped_attributes

Defined in:
lib/reactive_record/active_record/reactive_record/reactive_set_relationship_helpers.rb

#update_mapped_attributes(aggregation) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/reactive_record/active_record/reactive_record/reactive_set_relationship_helpers.rb', line 19

def update_mapped_attributes(aggregation)
  # insure the aggregate attr is initialized, clear the virt flag, the caller
  # will yield each of the matching attribute values
  attr = aggregation.attribute
  attributes[attr] ||= aggregation.klass.new if new?
  aggregate_record = attributes[attr]
  raise 'uninitialized aggregate attribute - should never happen' unless aggregate_record
  aggregate_backing_record = aggregate_record.backing_record
  aggregate_backing_record.virgin = false
  aggregation.mapped_attributes.each do |mapped_attribute|
    aggregate_backing_record.update_attribute(mapped_attribute, yield(mapped_attribute))
  end
end