Skip to content
Browse files
passing an instance of an AR object to find is deprecated
please pass the id of the AR object by calling `.id` on the model first.
  • Loading branch information
tenderlove committed Mar 13, 2014
1 parent d92ae6c commit d35f0033c7dec2b8d8b52058fb8db495d49596f7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
@@ -1,3 +1,6 @@
* Passing an Active Record object to `find` is now deprecated. Call `.id`
on the object first.

* Passing an Active Record object to `exists?` is now deprecated. Call `.id`
on the object first.

@@ -421,7 +421,11 @@ def find_with_ids(*ids)

def find_one(id)
id = if ActiveRecord::Base === id
if ActiveRecord::Base === id
id =
ActiveSupport::Deprecation.warn "You are passing an instance of ActiveRecord::Base to `find`." \
"Please pass the id of the object by calling `.id`"

column = columns_hash[primary_key]
substitute = connection.substitute_at(column, bind_values.length)
@@ -407,19 +407,19 @@ def test_eager_load_belongs_to_quotes_table_and_column_names

def test_eager_load_has_one_quotes_table_and_column_names
michael = Person.all.merge!(:includes => :favourite_reference).find(people(:michael))
michael = Person.all.merge!(:includes => :favourite_reference).find(people(:michael).id)
assert_no_queries{ assert_equal references(:michael_unicyclist), michael.favourite_reference}

def test_eager_load_has_many_quotes_table_and_column_names
michael = Person.all.merge!(:includes => :references).find(people(:michael))
michael = Person.all.merge!(:includes => :references).find(people(:michael).id)
assert_no_queries{ assert_equal references(:michael_magician,:michael_unicyclist), michael.references.sort_by(&:id) }

def test_eager_load_has_many_through_quotes_table_and_column_names
michael = Person.all.merge!(:includes => :jobs).find(people(:michael))
michael = Person.all.merge!(:includes => :jobs).find(people(:michael).id)
jobs(:magician, :unicyclist)
assert_no_queries{ assert_equal jobs(:unicyclist, :magician), }
@@ -637,7 +637,7 @@ def test_where_with_ar_object

def test_find_with_list_of_ar
author = Author.first
authors = Author.find([author])
authors = Author.find([])
assert_equal author, authors.first

@@ -223,7 +223,7 @@ def test_validate_case_insensitive_uniqueness
assert, "Should save t_utf8 as unique"

# If database hasn't UTF-8 character set, this test fails
if Topic.all.merge!(:select => 'LOWER(title) AS title').find(t_utf8).title == "я тоже уникальный!"
if Topic.all.merge!(:select => 'LOWER(title) AS title').find( == "я тоже уникальный!"
t2_utf8 ="title" => "я тоже УНИКАЛЬНЫЙ!")
assert !t2_utf8.valid?, "Shouldn't be valid"
assert !, "Shouldn't save t2_utf8 as unique"

0 comments on commit d35f003

Please sign in to comment.