Class: MassiveRecord::ORM::Persistence::Operations::Embedded::Reload

Inherits:
Object
  • Object
show all
Includes:
MassiveRecord::ORM::Persistence::Operations, OperationHelpers
Defined in:
lib/massive_record/orm/persistence/operations/embedded/reload.rb

Defined Under Namespace

Classes: UnsupportedNumberOfEmbeddedIn

Instance Attribute Summary

Attributes included from MassiveRecord::ORM::Persistence::Operations

#klass, #options, #record

Instance Method Summary collapse

Methods included from MassiveRecord::ORM::Persistence::Operations

atomic_operation, destroy, force, #initialize, insert, reload, suppress, suppressed?, update

Methods included from OperationHelpers

#embedded_in_proxies, #embedded_in_proxy_targets, #inverse_proxy_for, #raise_error_if_embedded_in_proxy_targets_are_missing, #row_for_record, #update_embedded

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/massive_record/orm/persistence/operations/embedded/reload.rb', line 13

def execute
  if record.persisted? && embeds_many_proxy_to_reload_from
    embeds_many_proxy_to_reload_from = inverse_proxy_for(embedded_in_proxies.first)
    embeds_many_proxy_to_reload_from.reload
    embeds_many_proxy_to_reload_from.find(record.id).tap do |reloaded_record|
      record.reinit_with({
        'attributes' => reloaded_record.attributes,
        'raw_data' => reloaded_record.raw_data
      })
    end

    true
  end
end