Module: ChronoModel::Patches::Relation

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

Instance Method Summary collapse

Methods included from AsOfTimeHolder

#as_of_time, #as_of_time!

Instance Method Details

#build_arelObject


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/chrono_model/patches.rb', line 68

def build_arel
  return super unless @_as_of_time

  super.tap do |arel|

    arel.join_sources.each do |join|
      # This case happens with nested includes, where the below
      # code has already replaced the join.left with a JoinNode.
      #
      next if join.left.respond_to?(:as_of_time)

      model = TimeMachine.chrono_models[join.left.table_name]
      next unless model

      join.left = JoinNode.new(join.left, model.history, @_as_of_time)
    end

  end
end

#build_preloaderObject

Build a preloader at the as_of_time of this relation


90
91
92
# File 'lib/chrono_model/patches.rb', line 90

def build_preloader
  ActiveRecord::Associations::Preloader.new(as_of_time: as_of_time)
end

#loadObject


56
57
58
59
60
# File 'lib/chrono_model/patches.rb', line 56

def load
  return super unless @_as_of_time && !loaded?

  super.each {|record| record.as_of_time!(@_as_of_time) }
end

#mergeObject


62
63
64
65
66
# File 'lib/chrono_model/patches.rb', line 62

def merge(*)
  return super unless @_as_of_time

  super.as_of_time!(@_as_of_time)
end