diff options
author | Steven Fenigstein <steve@navigatingcancer.com> | 2011-02-11 00:39:58 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-16 09:54:09 -0800 |
commit | 9b188c5bfe04349aa8ee0eeb2b53456601b8c3fc (patch) | |
tree | 97c30d3f5a577dea783c5b527c75449059b01348 /activerecord/lib | |
parent | c6fac7b449ad88a623d99487d2731dddc6555636 (diff) | |
download | rails-9b188c5bfe04349aa8ee0eeb2b53456601b8c3fc.tar.gz rails-9b188c5bfe04349aa8ee0eeb2b53456601b8c3fc.tar.bz2 rails-9b188c5bfe04349aa8ee0eeb2b53456601b8c3fc.zip |
removed an unnecessary second query when passing an ActiveRecord::Relation to a where clause. And added ability to use subselects in where clauses.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 61d9974570..80b5495569 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -18,7 +18,10 @@ module ActiveRecord attribute = table[column.to_sym] case value - when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation + when ActiveRecord::Relation + value.select_values = Array.wrap("#{value.klass.quoted_table_name}.id") if value.select_values.empty? + attribute.in(value.arel.ast) + when Array, ActiveRecord::Associations::AssociationCollection values = value.to_a.map { |x| x.is_a?(ActiveRecord::Base) ? x.id : x } |