Sha256: fb4c1a67158636a51047bc4751c31f235aae4d75625af0ab0d7a69f757b52d52
Contents?: true
Size: 1.27 KB
Versions: 8
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true require "active_record/associations/preloader" module ActiveRecord module ConnectionAdapters module SQLServer module CoreExt module LoaderQuery def load_records_for_keys(keys, &block) return super unless scope.connection.sqlserver? return [] if keys.empty? if association_key_name.is_a?(Array) query_constraints = Hash.new { |hsh, key| hsh[key] = Set.new } keys.each_with_object(query_constraints) do |values_set, constraints| association_key_name.zip(values_set).each do |key_name, value| constraints[key_name] << value end end scope.where(query_constraints).load(&block) else keys.each_slice(in_clause_length).flat_map do |slice| scope.where(association_key_name => slice).load(&block).records end end end def in_clause_length 10_000 end end end end end end ActiveSupport.on_load(:active_record) do mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::LoaderQuery ActiveRecord::Associations::Preloader::Association::LoaderQuery.prepend(mod) end
Version data entries
8 entries across 8 versions & 1 rubygems