diff options
author | Ben Woosley <ben.woosley@gmail.com> | 2012-05-28 09:52:27 -0700 |
---|---|---|
committer | Ben Woosley <ben.woosley@gmail.com> | 2012-06-10 17:51:17 -0700 |
commit | 340a93f5026ffb8e877024c23791e8a345605976 (patch) | |
tree | fc9bfb567c383f4e48314a13aee62e03b08f63c3 /activerecord | |
parent | d17fa452ec1993271ccc6e5035fb27b9c89513cf (diff) | |
download | rails-340a93f5026ffb8e877024c23791e8a345605976.tar.gz rails-340a93f5026ffb8e877024c23791e8a345605976.tar.bz2 rails-340a93f5026ffb8e877024c23791e8a345605976.zip |
Fix that #exists? raises ThrowResult when called with an empty limited
reflection.
ActiveRecord::FinderMethods#construct_limited_ids_condition will raise
ThrowResult if the limited reflection comes back empty. The other callers
of #construct_limited_ids_condition handle this exception (more specifically,
the callers of construct_relation_for*), but #exists? didn't until now.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 21a99800fe..1de69fce76 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -186,6 +186,8 @@ module ActiveRecord end connection.select_value(relation, "#{name} Exists", relation.bind_values) + rescue ThrowResult + false end protected diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 78da8778f0..0914d15c5e 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -69,7 +69,12 @@ class FinderTest < ActiveRecord::TestCase assert Topic.order(:id).uniq.exists? end - def test_does_not_exist_with_empty_table_and_no_args_given + def test_exists_with_includes_limit_and_empty_result + assert !Topic.includes(:replies).limit(0).exists? + assert !Topic.includes(:replies).limit(1).where('0 = 1').exists? + end + + def test_exists_with_empty_table_and_no_args_given Topic.delete_all assert !Topic.exists? end |