diff options
author | David Verhasselt <david@crowdway.com> | 2014-05-23 13:46:03 +0300 |
---|---|---|
committer | David Verhasselt <david@crowdway.com> | 2014-06-10 11:18:52 +0300 |
commit | 63fd88ca5c255a84b61ce81c41dfe9928ea101d9 (patch) | |
tree | 88d1e1b8bbae64312aea3b83f02f2426e906624f /activerecord/lib | |
parent | 90fb179cb3fb6f1decd7e42227cd8e0251832d7b (diff) | |
download | rails-63fd88ca5c255a84b61ce81c41dfe9928ea101d9.tar.gz rails-63fd88ca5c255a84b61ce81c41dfe9928ea101d9.tar.bz2 rails-63fd88ca5c255a84b61ce81c41dfe9928ea101d9.zip |
If a counter_cache exists, use it for #empty?
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 2727e23870..3ffc015975 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -41,6 +41,14 @@ module ActiveRecord end end + def empty? + if has_cached_counter? + size.zero? + else + super + end + end + private # Returns the number of records in this collection. |