diff options
author | Matthew Draper <matthew@trebex.net> | 2014-05-22 14:47:04 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2014-05-22 14:59:23 +0930 |
commit | 110d3d0c0bceddd05cab86c0463f0aa71df815cb (patch) | |
tree | 51f9140e099bd0af1d6ddb59e5bb62417bb35fa1 /activerecord/lib/active_record/null_relation.rb | |
parent | a0155b2f550985dce1f5bafbe62cfea9be212f57 (diff) | |
parent | 6d36c1dd05cc858dea92acbd7f3b476690878341 (diff) | |
download | rails-110d3d0c0bceddd05cab86c0463f0aa71df815cb.tar.gz rails-110d3d0c0bceddd05cab86c0463f0aa71df815cb.tar.bz2 rails-110d3d0c0bceddd05cab86c0463f0aa71df815cb.zip |
Merge pull request #14803 from kuldeepaggarwal/null_relation_sum_fix
Fixed a problem where `sum` used with a `group` was not returning a Hash.
Diffstat (limited to 'activerecord/lib/active_record/null_relation.rb')
-rw-r--r-- | activerecord/lib/active_record/null_relation.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/null_relation.rb b/activerecord/lib/active_record/null_relation.rb index 05d0c41678..807c301596 100644 --- a/activerecord/lib/active_record/null_relation.rb +++ b/activerecord/lib/active_record/null_relation.rb @@ -23,7 +23,7 @@ module ActiveRecord end def size - 0 + calculate :size, nil end def empty? @@ -47,14 +47,28 @@ module ActiveRecord end def sum(*) - 0 + calculate :sum, nil + end + + def average(*) + calculate :average, nil + end + + def minimum(*) + calculate :minimum, nil + end + + def maximum(*) + calculate :maximum, nil end def calculate(operation, _column_name, _options = {}) # TODO: Remove _options argument as soon we remove support to # activerecord-deprecated_finders. - if operation == :count + if [:count, :sum, :size].include? operation group_values.any? ? Hash.new : 0 + elsif [:average, :minimum, :maximum].include?(operation) && group_values.any? + Hash.new else nil end |