@@ -8,53 +8,6 @@ module ConnectionAdapters
88 module SQLServer
99 module CoreExt
1010 module Calculations
11- def calculate ( operation , column_name )
12- klass . with_connection do |connection |
13- if connection . sqlserver?
14- _calculate ( operation , column_name )
15- else
16- super
17- end
18- end
19- end
20-
21- private
22-
23- # Same as original `calculate` method except we don't perform PostgreSQL hack that removes ordering.
24- def _calculate ( operation , column_name )
25- operation = operation . to_s . downcase
26-
27- if @none
28- case operation
29- when "count" , "sum"
30- result = group_values . any? ? Hash . new : 0
31- return @async ? Promise ::Complete . new ( result ) : result
32- when "average" , "minimum" , "maximum"
33- result = group_values . any? ? Hash . new : nil
34- return @async ? Promise ::Complete . new ( result ) : result
35- end
36- end
37-
38- if has_include? ( column_name )
39- relation = apply_join_dependency
40-
41- if operation == "count"
42- unless distinct_value || distinct_select? ( column_name || select_for_count )
43- relation . distinct!
44- relation . select_values = Array ( klass . primary_key || table [ Arel . star ] )
45- end
46- # PostgreSQL: ORDER BY expressions must appear in SELECT list when using DISTINCT
47- # Start of monkey-patch
48- # relation.order_values = [] if group_values.empty?
49- # End of monkey-patch
50- end
51-
52- relation . calculate ( operation , column_name )
53- else
54- perform_calculation ( operation , column_name )
55- end
56- end
57-
5811 def build_count_subquery ( relation , column_name , distinct )
5912 klass . with_connection do |connection |
6013 relation = relation . unscope ( :order ) if connection . sqlserver?
0 commit comments