Make average compatible accross Ruby versions
Since Ruby 2.6.0 NilClass#to_d is returning `BigDecimal` 0.0, this breaks `average` compatibility with prior Ruby versions. This patch makes `average` return `nil` in all Ruby versions when there are no rows.
This commit is contained in:
parent
3f2c865731
commit
d237c7c72c
@ -401,7 +401,7 @@ def type_cast_calculated_value(value, type, operation = nil)
|
||||
case operation
|
||||
when "count" then value.to_i
|
||||
when "sum" then type.deserialize(value || 0)
|
||||
when "average" then value.respond_to?(:to_d) ? value.to_d : value
|
||||
when "average" then value&.respond_to?(:to_d) ? value.to_d : value
|
||||
else type.deserialize(value)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user