mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix PredicateBuilder clobbering select_values in subquery.
This commit is contained in:
parent
e2ae015952
commit
f74f5f7f00
2 changed files with 14 additions and 1 deletions
|
@ -19,7 +19,7 @@ module ActiveRecord
|
||||||
|
|
||||||
case value
|
case value
|
||||||
when ActiveRecord::Relation
|
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)
|
attribute.in(value.arel.ast)
|
||||||
when Array, ActiveRecord::Associations::CollectionProxy
|
when Array, ActiveRecord::Associations::CollectionProxy
|
||||||
values = value.to_a.map { |x|
|
values = value.to_a.map { |x|
|
||||||
|
|
|
@ -550,6 +550,19 @@ class RelationTest < ActiveRecord::TestCase
|
||||||
}
|
}
|
||||||
end
|
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
|
def test_find_all_using_where_with_relation_with_joins
|
||||||
david = authors(:david)
|
david = authors(:david)
|
||||||
assert_queries(1) {
|
assert_queries(1) {
|
||||||
|
|
Loading…
Reference in a new issue