Skip to content

Commit fd06686

Browse files
aidanharanwpolicarpo
authored andcommitted
Calculate should not remove ordering for MSSQL
1 parent c6308c2 commit fd06686

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ module ConnectionAdapters
66
module SQLServer
77
module CoreExt
88
module Calculations
9+
10+
# Same as original except we don't perform PostgreSQL hack that removes ordering.
11+
def calculate(operation, column_name)
12+
if has_include?(column_name)
13+
relation = apply_join_dependency
14+
15+
if operation.to_s.downcase == "count"
16+
unless distinct_value || distinct_select?(column_name || select_for_count)
17+
relation.distinct!
18+
relation.select_values = [ klass.primary_key || table[Arel.star] ]
19+
end
20+
end
21+
22+
relation.calculate(operation, column_name)
23+
else
24+
perform_calculation(operation, column_name)
25+
end
26+
end
27+
928
private
1029

1130
def build_count_subquery(relation, column_name, distinct)

0 commit comments

Comments
 (0)