Skip to content

Commit 19ae26d

Browse files
authored
Remove ActiveRecord::Relation#calculate patch (#1199)
1 parent c67ea94 commit 19ae26d

File tree

2 files changed

+5
-43
lines changed

2 files changed

+5
-43
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- [#1164](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1164) Fix composite primary key with different data type with triggers
66

7+
#### Changed
8+
9+
- [#1199](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1199) Remove ActiveRecord::Relation#calculate patch
10+
711
## v7.1.3
812

913
#### Fixed

Diff for: lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb

+1-43
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,9 @@ module ConnectionAdapters
88
module SQLServer
99
module CoreExt
1010
module Calculations
11-
def calculate(operation, column_name)
12-
if klass.connection.sqlserver?
13-
_calculate(operation, column_name)
14-
else
15-
super
16-
end
17-
end
18-
11+
1912
private
2013

21-
# Same as original `calculate` method except we don't perform PostgreSQL hack that removes ordering.
22-
def _calculate(operation, column_name)
23-
operation = operation.to_s.downcase
24-
25-
if @none
26-
case operation
27-
when "count", "sum"
28-
result = group_values.any? ? Hash.new : 0
29-
return @async ? Promise::Complete.new(result) : result
30-
when "average", "minimum", "maximum"
31-
result = group_values.any? ? Hash.new : nil
32-
return @async ? Promise::Complete.new(result) : result
33-
end
34-
end
35-
36-
if has_include?(column_name)
37-
relation = apply_join_dependency
38-
39-
if operation == "count"
40-
unless distinct_value || distinct_select?(column_name || select_for_count)
41-
relation.distinct!
42-
relation.select_values = [ klass.primary_key || table[Arel.star] ]
43-
end
44-
# PostgreSQL: ORDER BY expressions must appear in SELECT list when using DISTINCT
45-
# Start of monkey-patch
46-
# relation.order_values = [] if group_values.empty?
47-
# End of monkey-patch
48-
end
49-
50-
relation.calculate(operation, column_name)
51-
else
52-
perform_calculation(operation, column_name)
53-
end
54-
end
55-
5614
def build_count_subquery(relation, column_name, distinct)
5715
return super unless klass.connection.adapter_name == "SQLServer"
5816

0 commit comments

Comments
 (0)