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:
parent
09a48b2324
commit
fa21b73ebb
3 changed files with 3 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue