File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
lib/active_record/relation Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -376,8 +376,16 @@ def apply_join_dependency(eager_loading: group_values.empty?)
376
376
)
377
377
relation = except ( :includes , :eager_load , :preload ) . joins! ( join_dependency )
378
378
379
- reflections = join_dependency . reflections + joins_values . map { |joins_value | reflect_on_association ( joins_value ) } . reject ( &:blank? )
380
- if eager_loading && !using_limitable_reflections? ( reflections )
379
+ if eager_loading && !(
380
+ using_limitable_reflections? ( join_dependency . reflections ) &&
381
+ using_limitable_reflections? (
382
+ construct_join_dependency (
383
+ select_association_list ( joins_values ) . concat (
384
+ select_association_list ( left_outer_joins_values )
385
+ ) , nil
386
+ ) . reflections
387
+ )
388
+ )
381
389
if has_limit_or_offset?
382
390
limited_ids = limited_ids_for ( relation )
383
391
limited_ids . empty? ? relation . none! : relation . where! ( primary_key => limited_ids )
Original file line number Diff line number Diff line change @@ -1083,15 +1083,23 @@ def build_from
1083
1083
end
1084
1084
end
1085
1085
1086
- def valid_association_list ( associations )
1086
+ def select_association_list ( associations )
1087
+ result = [ ]
1087
1088
associations . each do |association |
1088
1089
case association
1089
1090
when Hash , Symbol , Array
1090
- # valid
1091
+ result << association
1091
1092
else
1092
- raise ArgumentError , "only Hash, Symbol and Array are allowed"
1093
+ yield if block_given?
1093
1094
end
1094
1095
end
1096
+ result
1097
+ end
1098
+
1099
+ def valid_association_list ( associations )
1100
+ select_association_list ( associations ) do
1101
+ raise ArgumentError , "only Hash, Symbol and Array are allowed"
1102
+ end
1095
1103
end
1096
1104
1097
1105
def build_left_outer_joins ( manager , outer_joins , aliases )
Original file line number Diff line number Diff line change @@ -1330,9 +1330,15 @@ def test_with_limiting_with_custom_select
1330
1330
end
1331
1331
1332
1332
def test_eager_load_for_no_has_many_with_limit_and_joins_for_has_many
1333
- relation = Post . eager_load ( :author ) . joins ( : comments)
1333
+ relation = Post . eager_load ( :author ) . joins ( comments : :post )
1334
1334
assert_equal 5 , relation . to_a . size
1335
- assert_equal relation . limit ( 5 ) . to_a . size , relation . to_a . size
1335
+ assert_equal 5 , relation . limit ( 5 ) . to_a . size
1336
+ end
1337
+
1338
+ def test_eager_load_for_no_has_many_with_limit_and_left_joins_for_has_many
1339
+ relation = Post . eager_load ( :author ) . left_joins ( comments : :post )
1340
+ assert_equal 11 , relation . to_a . size
1341
+ assert_equal 11 , relation . limit ( 11 ) . to_a . size
1336
1342
end
1337
1343
1338
1344
def test_find_one_message_on_primary_key
You can’t perform that action at this time.
0 commit comments