diff options
author | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2014-05-15 00:49:29 +0530 |
---|---|---|
committer | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2014-05-15 00:49:29 +0530 |
commit | 6d36c1dd05cc858dea92acbd7f3b476690878341 (patch) | |
tree | d227d7cafae0bc09f0386338460363db28ebc842 /activerecord/lib/active_record/null_relation.rb | |
parent | c279d0197ac7aa36a6cfedf50f67f6008cbce7b5 (diff) | |
download | rails-6d36c1dd05cc858dea92acbd7f3b476690878341.tar.gz rails-6d36c1dd05cc858dea92acbd7f3b476690878341.tar.bz2 rails-6d36c1dd05cc858dea92acbd7f3b476690878341.zip |
Fixed a problem where `sum`, `size`, `average`, `minimum` and `maximum` used
with a grouping 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 |