Module: ActiveRecord::Persistence

Defined in:
lib/activerecord-bitemporal/bitemporal.rb

Instance Method Summary collapse

Instance Method Details

#active_record_bitemporal_original_reloadObject

MEMO: Must be override ActiveRecord::Persistence#reload



362
# File 'lib/activerecord-bitemporal/bitemporal.rb', line 362

alias_method :active_record_bitemporal_original_reload, :reload

#reload(options = nil) ⇒ Object



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/activerecord-bitemporal/bitemporal.rb', line 364

def reload(options = nil)
  return active_record_bitemporal_original_reload(options) unless self.class.bi_temporal_model?

  self.class.connection.clear_query_cache

  fresh_object =
    ActiveRecord::Bitemporal.with_bitemporal_option(**bitemporal_option) {
      if apply_scoping?(options)
        _find_record(options)
      else
        self.class.unscoped { self.class.bitemporal_default_scope.scoping { _find_record(options) } }
      end
    }

  @association_cache = fresh_object.instance_variable_get(:@association_cache)
  @attributes = fresh_object.instance_variable_get(:@attributes)
  @new_record = false
  @previously_new_record = false
  # NOTE: Hook to copying swapped_id
  @_swapped_id = fresh_object.swapped_id
  self
end