Permalink
Browse files

Fix PredicateBuilder clobbering select_values in subquery.

  • Loading branch information...
1 parent e2ae015 commit f74f5f7f00bd591fbca0cbc2b847acb0ec420256 @ernie ernie committed Aug 20, 2011
View
2 activerecord/lib/active_record/relation/predicate_builder.rb
@@ -19,7 +19,7 @@ def self.build_from_hash(engine, attributes, default_table)
case value
when ActiveRecord::Relation
- value.select_values = [value.klass.arel_table[value.klass.primary_key]] if value.select_values.empty?
+ 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|
View
13 activerecord/test/cases/relations_test.rb
@@ -550,6 +550,19 @@ def test_find_all_using_where_with_relation_and_alternate_primary_key
}
end
+ def test_find_all_using_where_with_relation_does_not_alter_select_values
+ david = authors(:david)
+
+ subquery = Author.where(:id => david.id)
+
+ assert_queries(1) {
+ relation = Author.where(:id => subquery)
+ assert_equal [david], relation.all
+ }
+
+ assert_equal 0, subquery.select_values.size
+ end
+
def test_find_all_using_where_with_relation_with_joins
david = authors(:david)
assert_queries(1) {

0 comments on commit f74f5f7

Please sign in to comment.