mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Changed ActiveRecord::Base#exists? to invoke find_initial so that it is compatible with, and doesn't lose, :include scopes (references to eager loaded tables)
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#2543 state:committed]
This commit is contained in:
committed by
Michael Koziarski
parent
49a84ff69c
commit
afcbdfc15f
@@ -697,14 +697,9 @@ module ActiveRecord #:nodoc:
|
||||
# Person.exists?(['name LIKE ?', "%#{query}%"])
|
||||
# Person.exists?
|
||||
def exists?(id_or_conditions = {})
|
||||
connection.select_all(
|
||||
construct_finder_sql(
|
||||
:select => "#{quoted_table_name}.#{primary_key}",
|
||||
:conditions => expand_id_conditions(id_or_conditions),
|
||||
:limit => 1
|
||||
),
|
||||
"#{name} Exists"
|
||||
).size > 0
|
||||
find_initial(
|
||||
:select => "#{quoted_table_name}.#{primary_key}",
|
||||
:conditions => expand_id_conditions(id_or_conditions)) ? true : false
|
||||
end
|
||||
|
||||
# Creates an object (or multiple objects) and saves it to the database, if validations pass.
|
||||
|
||||
@@ -119,6 +119,12 @@ class FinderTest < ActiveRecord::TestCase
|
||||
Address.new(existing_address.street + "1", existing_address.city, existing_address.country))
|
||||
end
|
||||
|
||||
def test_exists_with_scoped_include
|
||||
Developer.with_scope(:find => { :include => :projects, :order => "projects.name" }) do
|
||||
assert Developer.exists?
|
||||
end
|
||||
end
|
||||
|
||||
def test_find_by_array_of_one_id
|
||||
assert_kind_of(Array, Topic.find([ 1 ]))
|
||||
assert_equal(1, Topic.find([ 1 ]).length)
|
||||
|
||||
Reference in New Issue
Block a user