Browse files

use quoted id of single AR::Base objects in predicates

  • Loading branch information...
1 parent bd94479 commit fc69c64c84c424576204f0100df9a1bba3b29160 @tenderlove tenderlove committed Nov 15, 2010
View
2 activerecord/lib/active_record/relation/predicate_builder.rb
@@ -30,6 +30,8 @@ def build_from_hash(attributes, default_table)
attribute.in(values)
when Range, Arel::Relation
attribute.in(value)
+ when ActiveRecord::Base
+ attribute.eq(value.quoted_id)
else
attribute.eq(value)
end
View
6 activerecord/test/cases/relations_test.rb
@@ -421,6 +421,12 @@ def test_find_in_empty_array
assert_blank authors.all
end
+ def test_where_with_ar_object
+ author = Author.first
+ authors = Author.scoped.where(:id => author)
+ assert_equal 1, authors.all.length
+ end
+
def test_exists
davids = Author.where(:name => 'David')
assert davids.exists?

0 comments on commit fc69c64

Please sign in to comment.