@@ -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