aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-11-09 12:09:37 +0000
committerJon Leighton <j@jonathanleighton.com>2012-11-09 12:09:37 +0000
commitedd94cee9af1688dd036fc58fd405adb30a5e0da (patch)
tree84decda9a75027ac05235930ea166dc1755bb890 /activerecord/lib
parent11b846eefb1e7128ae9c63035f6d559d50bd4563 (diff)
downloadrails-edd94cee9af1688dd036fc58fd405adb30a5e0da.tar.gz
rails-edd94cee9af1688dd036fc58fd405adb30a5e0da.tar.bz2
rails-edd94cee9af1688dd036fc58fd405adb30a5e0da.zip
Delegate all calculations to the scope.
So that the scope may be a NullRelation and return a result without executing a query. Fixes #7928
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb6
-rw-r--r--activerecord/lib/active_record/null_relation.rb4
2 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index e044099b72..1b746b46b7 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -28,6 +28,8 @@ module ActiveRecord
# is computed directly through SQL and does not trigger by itself the
# instantiation of the actual post records.
class CollectionProxy < Relation
+ delegate *ActiveRecord::Calculations.public_instance_methods, to: :scope
+
def initialize(association) #:nodoc:
@association = association
super association.klass, association.klass.arel_table
@@ -965,10 +967,6 @@ module ActiveRecord
proxy_association.reload
self
end
-
- def pluck(column_names)
- scope.pluck(column_names)
- end
end
end
end
diff --git a/activerecord/lib/active_record/null_relation.rb b/activerecord/lib/active_record/null_relation.rb
index f8f7a6c976..711fc8b883 100644
--- a/activerecord/lib/active_record/null_relation.rb
+++ b/activerecord/lib/active_record/null_relation.rb
@@ -50,6 +50,10 @@ module ActiveRecord
0
end
+ def sum(*)
+ 0
+ end
+
def calculate(_operation, _column_name, _options = {})
nil
end