Skip to content

Commit 98f608b

Browse files
committed
Remove deprecation for aggregations that are grouping in duplicated fields
Now we will apply the behavior that is intended to Rails 7, which ignores the duplicated fields.
1 parent cf269d5 commit 98f608b

File tree

2 files changed

+14
-35
lines changed

2 files changed

+14
-35
lines changed

activerecord/lib/active_record/relation/calculations.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,6 @@ def execute_grouped_calculation(operation, column_name, distinct) # :nodoc:
329329
group_fields = group_values
330330
group_fields = group_fields.uniq if group_fields.size > 1
331331

332-
unless group_fields == group_values
333-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
334-
`#{operation}` with group by duplicated fields does no longer affect to result in Rails 7.0.
335-
To migrate to Rails 7.0's behavior, use `uniq!(:group)` to deduplicate group fields
336-
(`#{klass.name&.tableize || klass.table_name}.uniq!(:group).#{operation}(#{column_name.inspect})`).
337-
MSG
338-
group_fields = group_values
339-
end
340-
341332
if group_fields.size == 1 && group_fields.first.respond_to?(:to_sym)
342333
association = klass._reflect_on_association(group_fields.first)
343334
associated = association && association.belongs_to? # only count belongs_to associations

activerecord/test/cases/calculations_test.rb

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,36 +159,24 @@ def test_group_by_multiple_same_field
159159
assert_equal expected, accounts.merge!(accounts).uniq!(:group).sum(:credit_limit)
160160

161161
expected = {
162-
[nil, nil] => 50,
163-
[1, 1] => 50,
164-
[2, 2] => 60,
165-
[6, 6] => 55,
166-
[9, 9] => 53
162+
nil => 50,
163+
1 => 50,
164+
2 => 60,
165+
6 => 55,
166+
9 => 53
167167
}
168-
message = <<-MSG.squish
169-
`maximum` with group by duplicated fields does no longer affect to result in Rails 7.0.
170-
To migrate to Rails 7.0's behavior, use `uniq!(:group)` to deduplicate group fields
171-
(`accounts.uniq!(:group).maximum(:credit_limit)`).
172-
MSG
173-
assert_deprecated(message) do
174-
assert_equal expected, accounts.merge!(accounts).maximum(:credit_limit)
175-
end
168+
169+
assert_equal expected, accounts.merge!(accounts).maximum(:credit_limit)
176170

177171
expected = {
178-
[nil, nil, nil, nil] => 50,
179-
[1, 1, 1, 1] => 50,
180-
[2, 2, 2, 2] => 60,
181-
[6, 6, 6, 6] => 50,
182-
[9, 9, 9, 9] => 53
172+
nil => 50,
173+
1 => 50,
174+
2 => 60,
175+
6 => 50,
176+
9 => 53
183177
}
184-
message = <<-MSG.squish
185-
`minimum` with group by duplicated fields does no longer affect to result in Rails 7.0.
186-
To migrate to Rails 7.0's behavior, use `uniq!(:group)` to deduplicate group fields
187-
(`accounts.uniq!(:group).minimum(:credit_limit)`).
188-
MSG
189-
assert_deprecated(message) do
190-
assert_equal expected, accounts.merge!(accounts).minimum(:credit_limit)
191-
end
178+
179+
assert_equal expected, accounts.merge!(accounts).minimum(:credit_limit)
192180
end
193181

194182
def test_should_generate_valid_sql_with_joins_and_group

0 commit comments

Comments
 (0)