Sha256: f454037a39baff7956dabce3fa45f01f5ed049763235cdf2b66b1da4d9d709fc

Contents?: true

Size: 576 Bytes

Versions: 4

Compression:

Stored size: 576 Bytes

Contents

module TemporalTables
  # Uses the at time when fetching preloaded records
  module PreloaderExtensions
    def build_scope
      # It seems the at time can be in either of these places, but not both,
      # depending on when the preloading happens to be done
      at_time = @owners.first.at_value if @owners.first.respond_to?(:at_value)
      at_time ||= Thread.current[:at_time]

      if at_time
        super.at(at_time)
      else
        super
      end
    end
  end
end

ActiveRecord::Associations::Preloader::Association.prepend TemporalTables::PreloaderExtensions

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
temporal_tables-0.8.1 lib/temporal_tables/preloader_extensions.rb
temporal_tables-0.8.0 lib/temporal_tables/preloader_extensions.rb
temporal_tables-0.7.1 lib/temporal_tables/preloader_extensions.rb
temporal_tables-0.7.0 lib/temporal_tables/preloader_extensions.rb