Skip to content
Browse files

Merge pull request #6521 from Empact/throw-result

Fix that #exists? can blow up with ThrowResult exception
  • Loading branch information...
2 parents d17fa45 + 340a93f commit f48e7676e9b70884c309d3170b7ae8867e4bd252 @rafaelfranca rafaelfranca committed Jun 10, 2012
View
2 activerecord/lib/active_record/relation/finder_methods.rb
@@ -186,6 +186,8 @@ def exists?(id = false)
end
connection.select_value(relation, "#{name} Exists", relation.bind_values)
+ rescue ThrowResult
+ false
end
protected
View
7 activerecord/test/cases/finder_test.rb
@@ -69,7 +69,12 @@ def test_exists_with_order
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

0 comments on commit f48e767

Please sign in to comment.
Something went wrong with that request. Please try again.