Sha256: 7e9685e2a2cf8426fe6c7600051ce3911df43ffa962d6388cb9f52120fcd5f10

Contents?: true

Size: 607 Bytes

Versions: 9

Compression:

Stored size: 607 Bytes

Contents

# frozen_string_literal: true

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

9 entries across 9 versions & 1 rubygems

Version Path
temporal_tables-3.0.2 lib/temporal_tables/preloader_extensions.rb
temporal_tables-3.0.1 lib/temporal_tables/preloader_extensions.rb
temporal_tables-3.0.0 lib/temporal_tables/preloader_extensions.rb
temporal_tables-3.0.0.pre.rc.1 lib/temporal_tables/preloader_extensions.rb
temporal_tables-2.0.0 lib/temporal_tables/preloader_extensions.rb
temporal_tables-1.1.0 lib/temporal_tables/preloader_extensions.rb
temporal_tables-1.0.3 lib/temporal_tables/preloader_extensions.rb
temporal_tables-1.0.2 lib/temporal_tables/preloader_extensions.rb
temporal_tables-1.0.1 lib/temporal_tables/preloader_extensions.rb