aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnie Miller <ernie@metautonomo.us>2011-08-20 13:16:39 -0400
committerErnie Miller <ernie@metautonomo.us>2011-08-20 13:16:39 -0400
commitf74f5f7f00bd591fbca0cbc2b847acb0ec420256 (patch)
tree464ebbcb2c9e64ed2a7f1c874b2fbed9ea71f8fd
parente2ae015952c5bdcca044504b5be1c13a518eeaac (diff)
downloadrails-f74f5f7f00bd591fbca0cbc2b847acb0ec420256.tar.gz
rails-f74f5f7f00bd591fbca0cbc2b847acb0ec420256.tar.bz2
rails-f74f5f7f00bd591fbca0cbc2b847acb0ec420256.zip
Fix PredicateBuilder clobbering select_values in subquery.
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb13
2 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index dc8667b5cd..7e8ddd1b5d 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -19,7 +19,7 @@ module ActiveRecord
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|
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 711b07b113..615551a279 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -550,6 +550,19 @@ class RelationTest < ActiveRecord::TestCase
}
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) {