diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2014-07-15 08:34:44 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2014-07-15 08:34:44 -0700 |
commit | 473b09f6160a4663ded59d529d47be219eb18d9a (patch) | |
tree | 38346d96baf098597a2b7e7b75dff931c21ece00 /activerecord/lib | |
parent | ebb95018a71631a964774a594a087591c75f181e (diff) | |
parent | 63fd88ca5c255a84b61ce81c41dfe9928ea101d9 (diff) | |
download | rails-473b09f6160a4663ded59d529d47be219eb18d9a.tar.gz rails-473b09f6160a4663ded59d529d47be219eb18d9a.tar.bz2 rails-473b09f6160a4663ded59d529d47be219eb18d9a.zip |
Merge pull request #15266 from dv/use_counter_cache_for_empty_call
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 453615ba87..2a97d0ed31 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. |