From 63fd88ca5c255a84b61ce81c41dfe9928ea101d9 Mon Sep 17 00:00:00 2001 From: David Verhasselt Date: Fri, 23 May 2014 13:46:03 +0300 Subject: If a counter_cache exists, use it for #empty? --- .../lib/active_record/associations/has_many_association.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/lib/active_record/associations') 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. -- cgit v1.2.3