Sha256: c084cd01c85c9abb551050cf182f148a8c8e2a171000d9bcff01bc373d3083a2

Contents?: true

Size: 856 Bytes

Versions: 4

Compression:

Stored size: 856 Bytes

Contents

require "active_record/associations/preloader/association"

module ActiveRecord::Turntable
  module ActiveRecordExt
    module AssociationPreloader
      include ShardingCondition
      if Util.ar52_or_later?
        def build_scope
          returning_scope = super
          if should_use_shard_key?
            returning_scope = returning_scope.where(klass.turntable_shard_key => owners.map(&foreign_shard_key.to_sym).uniq)
          end
          returning_scope

        end
      else
        # @note Override to add sharding condition on preload
        def records_for(ids)
          returning_scope = super
          if should_use_shard_key?
            returning_scope = returning_scope.where(klass.turntable_shard_key => owners.map(&foreign_shard_key.to_sym).uniq)
          end
          returning_scope
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-turntable-4.4.1 lib/active_record/turntable/active_record_ext/association_preloader.rb
activerecord-turntable-4.4.0 lib/active_record/turntable/active_record_ext/association_preloader.rb
activerecord-turntable-4.3.0 lib/active_record/turntable/active_record_ext/association_preloader.rb
activerecord-turntable-4.2.0 lib/active_record/turntable/active_record_ext/association_preloader.rb