aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2013-10-19 13:07:09 -0700
committerSantiago Pastorino <santiago@wyeworks.com>2013-10-19 13:07:09 -0700
commitcc8d14827d117ed7da7a17c4a057a8e5f71625ca (patch)
tree5998a224b53e59df9d42900a7fe9fdbd17bfe376 /activerecord
parentdb82e1d0bb21c2a13354b97733c09737719e946b (diff)
parent4ba9c508ec1d59dd43154022479a37558f8c19f3 (diff)
downloadrails-cc8d14827d117ed7da7a17c4a057a8e5f71625ca.tar.gz
rails-cc8d14827d117ed7da7a17c4a057a8e5f71625ca.tar.bz2
rails-cc8d14827d117ed7da7a17c4a057a8e5f71625ca.zip
Merge pull request #12533 from szimek/use_exists_in_relation_empty
In Relation#empty? use #exists? instead of #count.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/relation.rb3
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.