From 4ba9c508ec1d59dd43154022479a37558f8c19f3 Mon Sep 17 00:00:00 2001 From: Szymon Nowak Date: Mon, 14 Oct 2013 19:51:29 +0200 Subject: [PATCH] In Relation#empty? use #exists? instead of #count. --- activerecord/CHANGELOG.md | 4 ++++ activerecord/lib/active_record/relation.rb | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 815e7c71fe..22a37810bc 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Make `Relation#empty?` use `exists?` instead of `count`. + + *Szymon Nowak* + * `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`. *Kenta Okamoto* diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index cfaf566ec4..81548117b0 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -244,8 +244,7 @@ module ActiveRecord def empty? return @records.empty? if loaded? - c = count(:all) - c.respond_to?(:zero?) ? c.zero? : c.empty? + limit_value == 0 ? true : !exists? end # Returns true if there are any records.