File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
lib/active_record/relation Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1+ * Fix referencing wrong table aliases while joining tables of has many through
2+ association (only when calling calculation methods).
3+
4+ Fixes #19276 .
5+
6+ * pinglamb*
7+
18* Don't attempt to update counter caches, when the column wasn't selected.
29
310 Fixes #19437 .
Original file line number Diff line number Diff line change @@ -379,7 +379,7 @@ def construct_join_dependency(joins = [])
379379 def construct_relation_for_association_calculations
380380 from = arel . froms . first
381381 if Arel ::Table === from
382- apply_join_dependency ( self , construct_join_dependency )
382+ apply_join_dependency ( self , construct_join_dependency ( joins_values ) )
383383 else
384384 # FIXME: as far as I can tell, `from` will always be an Arel::Table.
385385 # There are no tests that test this branch, but presumably it's
Original file line number Diff line number Diff line change 1111require 'models/speedometer'
1212require 'models/ship_part'
1313require 'models/treasure'
14+ require 'models/developer'
15+ require 'models/comment'
16+ require 'models/rating'
17+ require 'models/post'
1418
1519class NumericData < ActiveRecord ::Base
1620 self . table_name = 'numeric_data'
@@ -631,4 +635,11 @@ def test_grouped_calculation_with_polymorphic_relation
631635
632636 assert_equal ( { "has trinket" => part . id } , ShipPart . joins ( :trinkets ) . group ( "ship_parts.name" ) . sum ( :id ) )
633637 end
638+
639+ def test_should_reference_correct_aliases_while_joining_tables_of_has_many_through_association
640+ assert_nothing_raised ActiveRecord ::StatementInvalid do
641+ developer = Developer . create! ( name : 'developer' )
642+ developer . ratings . includes ( comment : :post ) . where ( posts : { id : 1 } ) . count
643+ end
644+ end
634645end
You can’t perform that action at this time.
0 commit comments