aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-11-15 14:35:28 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-15 14:35:38 -0800
commitdcdfc84f55ea1a7880a30f63b6517745310d24eb (patch)
treecd2de11ee2f74b7a5ac47526a2c30ecc8dfc7b5b /activerecord
parente4591489d13a27e2f905988be02a7d48fb7a0664 (diff)
downloadrails-dcdfc84f55ea1a7880a30f63b6517745310d24eb.tar.gz
rails-dcdfc84f55ea1a7880a30f63b6517745310d24eb.tar.bz2
rails-dcdfc84f55ea1a7880a30f63b6517745310d24eb.zip
use quoted id of single AR::Base objects in predicates
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb6
2 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index c5428dccd6..2eda404490 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -25,6 +25,8 @@ module ActiveRecord
attribute.in(values)
when Range, Arel::Relation
attribute.in(value)
+ when ActiveRecord::Base
+ attribute.eq(value.quoted_id)
else
attribute.eq(value)
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index b44c716db8..13c26a0c15 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -426,6 +426,12 @@ class RelationTest < ActiveRecord::TestCase
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?