aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyan Bates <ryan@railscasts.com>2008-05-27 07:31:53 -0700
committerPratik Naik <pratiknaik@gmail.com>2008-05-28 11:02:07 +0100
commitc2fbcba16d2349285368c86b849db946dc0e7d57 (patch)
tree3cf328f85d012018e028c1abf42ece6b47d830c8 /activerecord/lib
parent888a2927b65889465ce7a1a71e87d37640a2b41b (diff)
downloadrails-c2fbcba16d2349285368c86b849db946dc0e7d57.tar.gz
rails-c2fbcba16d2349285368c86b849db946dc0e7d57.tar.bz2
rails-c2fbcba16d2349285368c86b849db946dc0e7d57.zip
Ensure named_scope#empty? uses count query. [#262 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/named_scope.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 69b7da7700..b0c8a8b815 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -102,7 +102,7 @@ module ActiveRecord
attr_reader :proxy_scope, :proxy_options
[].methods.each do |m|
- unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|find|count|sum|average|maximum|minimum|paginate|first|last)/
+ unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|find|count|sum|average|maximum|minimum|paginate|first|last|empty?)/
delegate m, :to => :proxy_found
end
end
@@ -135,6 +135,10 @@ module ActiveRecord
end
end
+ def empty?
+ @found ? @found.empty? : count.zero?
+ end
+
protected
def proxy_found
@found || load_found