@@ -8,23 +8,25 @@ module SQLServer
8
8
module CoreExt
9
9
module LoaderQuery
10
10
def load_records_for_keys ( keys , &block )
11
- return super unless scope . connection . sqlserver?
11
+ scope . with_connection do |connection |
12
+ return super unless connection . sqlserver?
12
13
13
- return [ ] if keys . empty?
14
+ return [ ] if keys . empty?
14
15
15
- if association_key_name . is_a? ( Array )
16
- query_constraints = Hash . new { |hsh , key | hsh [ key ] = Set . new }
16
+ if association_key_name . is_a? ( Array )
17
+ query_constraints = Hash . new { |hsh , key | hsh [ key ] = Set . new }
17
18
18
- keys . each_with_object ( query_constraints ) do |values_set , constraints |
19
- association_key_name . zip ( values_set ) . each do |key_name , value |
20
- constraints [ key_name ] << value
19
+ keys . each_with_object ( query_constraints ) do |values_set , constraints |
20
+ association_key_name . zip ( values_set ) . each do |key_name , value |
21
+ constraints [ key_name ] << value
22
+ end
21
23
end
22
- end
23
24
24
- scope . where ( query_constraints ) . load ( &block )
25
- else
26
- keys . each_slice ( in_clause_length ) . flat_map do |slice |
27
- scope . where ( association_key_name => slice ) . load ( &block ) . records
25
+ scope . where ( query_constraints ) . load ( &block )
26
+ else
27
+ keys . each_slice ( in_clause_length ) . flat_map do |slice |
28
+ scope . where ( association_key_name => slice ) . load ( &block ) . records
29
+ end
28
30
end
29
31
end
30
32
end
0 commit comments