aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-24 00:24:49 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-24 11:08:16 +0000
commit35202aa6911679cccb8187d12996e3f30661385c (patch)
tree13664cc913a4412557e4d4a3036377acfb57e450 /activerecord
parenta1ee3ac654078ef57832b8e9833ac13afcb944fa (diff)
downloadrails-35202aa6911679cccb8187d12996e3f30661385c.tar.gz
rails-35202aa6911679cccb8187d12996e3f30661385c.tar.bz2
rails-35202aa6911679cccb8187d12996e3f30661385c.zip
Make PredicateBuilder recognise AR::Model
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb4
-rw-r--r--activerecord/test/cases/inclusion_test.rb6
2 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index a789f48725..eee198e760 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -22,7 +22,7 @@ module ActiveRecord
value = value.select(value.klass.arel_table[value.klass.primary_key]) if value.select_values.empty?
attribute.in(value.arel.ast)
when Array, ActiveRecord::Associations::CollectionProxy
- values = value.to_a.map {|x| x.is_a?(ActiveRecord::Base) ? x.id : x}
+ values = value.to_a.map {|x| x.is_a?(ActiveRecord::Model) ? x.id : x}
ranges, values = values.partition {|v| v.is_a?(Range) || v.is_a?(Arel::Relation)}
array_predicates = ranges.map {|range| attribute.in(range)}
@@ -41,7 +41,7 @@ module ActiveRecord
array_predicates.inject {|composite, predicate| composite.or(predicate)}
when Range, Arel::Relation
attribute.in(value)
- when ActiveRecord::Base
+ when ActiveRecord::Model
attribute.eq(value.id)
when Class
# FIXME: I think we need to deprecate this behavior
diff --git a/activerecord/test/cases/inclusion_test.rb b/activerecord/test/cases/inclusion_test.rb
index cc037e925d..70f402024b 100644
--- a/activerecord/test/cases/inclusion_test.rb
+++ b/activerecord/test/cases/inclusion_test.rb
@@ -23,6 +23,12 @@ class BasicInclusionModelTest < ActiveRecord::TestCase
t = Teapot.create!(:name => "Ronnie Kemper")
assert Teapot.exists?(t)
end
+
+ def test_predicate_builder
+ t = Teapot.create!(:name => "Bob")
+ assert_equal "Bob", Teapot.where(:id => [t]).first.name
+ assert_equal "Bob", Teapot.where(:id => t).first.name
+ end
end
class InclusionUnitTest < ActiveRecord::TestCase