aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/named_scope.rb
diff options
context:
space:
mode:
authorTom Stuart <tom@obsess.com>2008-08-29 15:11:25 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-08-29 22:18:49 +0100
commit7f179f8540ab92dbd9d3e650b465de5b694d93d4 (patch)
tree913eb8d2984c33f770c315c533cb339e7058d1d9 /activerecord/lib/active_record/named_scope.rb
parentc0361344d95162cd8573592d60e52986eaca0377 (diff)
downloadrails-7f179f8540ab92dbd9d3e650b465de5b694d93d4.tar.gz
rails-7f179f8540ab92dbd9d3e650b465de5b694d93d4.tar.bz2
rails-7f179f8540ab92dbd9d3e650b465de5b694d93d4.zip
Make NamedScope#size behave identically to AssociationCollection#size. [#933 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.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 7397d70279..d7e152ed1d 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -101,7 +101,7 @@ module ActiveRecord
class Scope
attr_reader :proxy_scope, :proxy_options
- NON_DELEGATE_METHODS = %w(nil? send object_id class extend find count sum average maximum minimum paginate first last empty? any? respond_to?).to_set
+ NON_DELEGATE_METHODS = %w(nil? send object_id class extend find size count sum average maximum minimum paginate first last empty? any? respond_to?).to_set
[].methods.each do |m|
unless m =~ /^__/ || NON_DELEGATE_METHODS.include?(m.to_s)
delegate m, :to => :proxy_found
@@ -136,6 +136,10 @@ module ActiveRecord
end
end
+ def size
+ @found ? @found.length : count
+ end
+
def empty?
@found ? @found.empty? : count.zero?
end