Module: ChronoModel::Patches::Relation

Includes:
AsOfTimeHolder
Defined in:
lib/chrono_model/patches/relation.rb

Instance Method Summary collapse

Methods included from AsOfTimeHolder

#as_of_time, #as_of_time!

Instance Method Details

#empty_scope?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/chrono_model/patches/relation.rb', line 20

def empty_scope?
  return super unless @_as_of_time

  @values == klass.unscoped.as_of(as_of_time).values
end

#find_nthObject



45
46
47
48
49
# File 'lib/chrono_model/patches/relation.rb', line 45

def find_nth(*)
  return super unless try(:history?)

  with_hid_pkey { super }
end

#lastObject



51
52
53
54
55
# File 'lib/chrono_model/patches/relation.rb', line 51

def last(*)
  return super unless try(:history?)

  with_hid_pkey { super }
end

#load(&block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chrono_model/patches/relation.rb', line 26

def load(&block)
  return super unless @_as_of_time && (!loaded? || scheduled?)

  records = super

  records.each do |record|
    record.as_of_time!(@_as_of_time)
    propagate_as_of_time_to_includes(record)
  end

  self
end

#mergeObject



39
40
41
42
43
# File 'lib/chrono_model/patches/relation.rb', line 39

def merge(*)
  return super unless @_as_of_time

  super.as_of_time!(@_as_of_time)
end

#preload_associations(records) ⇒ Object

:nodoc:



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/chrono_model/patches/relation.rb', line 8

def preload_associations(records) # :nodoc:
  preload = preload_values
  preload += includes_values unless eager_loading?
  scope = StrictLoadingScope if strict_loading_value

  preload.each do |associations|
    ActiveRecord::Associations::Preloader.new(
      records: records, associations: associations, scope: scope, model: model, as_of_time: as_of_time
    ).call
  end
end