Browse files

Return false for exists? with new records - fixes #6199.

  • Loading branch information...
1 parent 09a48b2 commit fa21b73ebb8339ad388f149c817c433b6254d490 @pixeltrix pixeltrix committed May 10, 2012
View
3 activerecord/lib/active_record/relation/finder_methods.rb
@@ -170,9 +170,8 @@ def all
# Person.exists?(['name LIKE ?', "%#{query}%"])
# Person.exists?
def exists?(id = false)
- return false if id.nil?
-
id = id.id if ActiveRecord::Model === id
+ return false if id.nil?
join_dependency = construct_join_dependency_for_association_find
relation = construct_relation_for_association_find(join_dependency)
View
1 activerecord/test/cases/finder_test.rb
@@ -32,6 +32,7 @@ def test_exists
assert Topic.exists?(:author_name => "Mary", :approved => true)
assert Topic.exists?(["parent_id = ?", 1])
assert !Topic.exists?(45)
+ assert !Topic.exists?(Topic.new)
begin
assert !Topic.exists?("foo")
View
1 activerecord/test/cases/relations_test.rb
@@ -644,6 +644,7 @@ def test_exists
assert ! davids.exists?(authors(:mary).id)
assert ! davids.exists?("42")
assert ! davids.exists?(42)
+ assert ! davids.exists?(davids.new)
fake = Author.where(:name => 'fake author')
assert ! fake.exists?

0 comments on commit fa21b73

Please sign in to comment.