1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

This commit is contained in:
Andrew White 2012-05-10 23:16:40 +01:00
parent 09a48b2324
commit fa21b73ebb
3 changed files with 3 additions and 2 deletions

View file

@ -170,9 +170,8 @@ module ActiveRecord
# 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 file

@ -32,6 +32,7 @@ class FinderTest < ActiveRecord::TestCase
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 file

@ -644,6 +644,7 @@ class RelationTest < ActiveRecord::TestCase
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?