aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/named_scope.rb
diff options
context:
space:
mode:
authorJan De Poorter <jan@defv.be>2008-07-23 12:50:16 +0200
committerPratik Naik <pratiknaik@gmail.com>2008-07-23 12:02:17 +0100
commit93e10f9911fb2a096681ee0a0bc82487a9a06c44 (patch)
tree92bcb41503ea63aeabcd0354da430630cbf3a683 /activerecord/lib/active_record/named_scope.rb
parent2681685450631238511cfc3c2f0fa044c1f8033a (diff)
downloadrails-93e10f9911fb2a096681ee0a0bc82487a9a06c44.tar.gz
rails-93e10f9911fb2a096681ee0a0bc82487a9a06c44.tar.bz2
rails-93e10f9911fb2a096681ee0a0bc82487a9a06c44.zip
Ensure NamedScope#any? uses COUNT query wherever possible. [#680 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/named_scope.rb')
-rw-r--r--activerecord/lib/active_record/named_scope.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 080e3d0f5e..d5a1c5fe08 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -103,7 +103,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|empty?)/
+ unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|find|count|sum|average|maximum|minimum|paginate|first|last|empty?|any?)/
delegate m, :to => :proxy_found
end
end
@@ -140,6 +140,14 @@ module ActiveRecord
@found ? @found.empty? : count.zero?
end
+ def any?
+ if block_given?
+ proxy_found.any? { |*block_args| yield(*block_args) }
+ else
+ !empty?
+ end
+ end
+
protected
def proxy_found
@found || load_found