Module: ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::LoaderQuery

Defined in:
lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb

Instance Method Summary collapse

Instance Method Details

#in_clause_lengthObject



34
35
36
# File 'lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb', line 34

def in_clause_length
  10_000
end

#load_records_for_keys(keys, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb', line 10

def load_records_for_keys(keys, &block)
  scope.with_connection do |connection|
    return super unless 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
end