diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-29 12:15:28 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-29 12:15:28 +0530 |
commit | f290e685f0497427b348a2fae760300429d5f0cd (patch) | |
tree | 2a1b9e53fd55c5800a26367e64d333dcf16ec0ef /activerecord/lib | |
parent | 13989ff8c690b9b9e5282bd4098666c909ea64d3 (diff) | |
download | rails-f290e685f0497427b348a2fae760300429d5f0cd.tar.gz rails-f290e685f0497427b348a2fae760300429d5f0cd.tar.bz2 rails-f290e685f0497427b348a2fae760300429d5f0cd.zip |
Add Relation#size and Relation#empty?
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index c6c63291c9..52a8bea567 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -219,6 +219,14 @@ module ActiveRecord end end + def size + loaded? ? @records.length : count + end + + def empty? + loaded? ? @records.empty? : count.zero? + end + def destroy_all to_a.each {|object| object.destroy} reset |