Skip to content

Commit

Permalink
Fix tests in NullRelationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Sep 19, 2023
1 parent 8d9b02a commit 4762adc
Showing 1 changed file with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,41 @@ module ConnectionAdapters
module SQLServer
module CoreExt
module Calculations
# Same as original except we don't perform PostgreSQL hack that removes ordering.
def calculate(operation, column_name)
return super unless klass.connection.adapter_name == "SQLServer"
if klass.connection.sqlserver?
_calculate(operation, column_name)
else
super
end
end

private

# Same as original `calculate` method except we don't perform PostgreSQL hack that removes ordering.
def _calculate(operation, column_name)
operation = operation.to_s.downcase

if @none
case operation
when "count", "sum"
result = group_values.any? ? Hash.new : 0
return @async ? Promise::Complete.new(result) : result
when "average", "minimum", "maximum"
result = group_values.any? ? Hash.new : nil
return @async ? Promise::Complete.new(result) : result
end
end

if has_include?(column_name)
relation = apply_join_dependency

if operation.to_s.downcase == "count"
if operation == "count"
unless distinct_value || distinct_select?(column_name || select_for_count)
relation.distinct!
relation.select_values = [klass.primary_key || table[Arel.star]]
relation.select_values = [ klass.primary_key || table[Arel.star] ]
end
# PostgreSQL: ORDER BY expressions must appear in SELECT list when using DISTINCT
# relation.order_values = [] if group_values.empty?
end

relation.calculate(operation, column_name)
Expand All @@ -28,8 +51,6 @@ def calculate(operation, column_name)
end
end

private

def build_count_subquery(relation, column_name, distinct)
return super unless klass.connection.adapter_name == "SQLServer"

Expand Down

0 comments on commit 4762adc

Please sign in to comment.