Skip to content

Commit bd6eacb

Browse files
committed
Fix average calculation in ruby 2.6
Ruby 2.6 added `to_d` to BigDecimal and it was causing some tests to fail because of that. See rails/rails#34858
1 parent 1bd52f1 commit bd6eacb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ module Calculations
1111
def build_count_subquery(relation, column_name, distinct)
1212
super(relation.unscope(:order), column_name, distinct)
1313
end
14+
15+
def type_cast_calculated_value(value, type, operation = nil)
16+
case operation
17+
when "count" then value.to_i
18+
when "sum" then type.deserialize(value || 0)
19+
when "average" then value&.respond_to?(:to_d) ? value.to_d : value
20+
else type.deserialize(value)
21+
end
22+
end
1423
end
1524
end
1625
end

0 commit comments

Comments
 (0)