mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fix assumption of primary key name in PredicateBuilder subquery.
This commit is contained in:
@@ -19,7 +19,7 @@ module ActiveRecord
|
||||
|
||||
case value
|
||||
when ActiveRecord::Relation
|
||||
value.select_values = [value.klass.arel_table['id']] if value.select_values.empty?
|
||||
value.select_values = [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|
|
||||
|
||||
@@ -540,6 +540,16 @@ class RelationTest < ActiveRecord::TestCase
|
||||
}
|
||||
end
|
||||
|
||||
def test_find_all_using_where_with_relation_and_alternate_primary_key
|
||||
cool_first = minivans(:cool_first)
|
||||
# switching the lines below would succeed in current rails
|
||||
# assert_queries(2) {
|
||||
assert_queries(1) {
|
||||
relation = Minivan.where(:minivan_id => Minivan.where(:name => cool_first.name))
|
||||
assert_equal [cool_first], relation.all
|
||||
}
|
||||
end
|
||||
|
||||
def test_find_all_using_where_with_relation_with_joins
|
||||
david = authors(:david)
|
||||
assert_queries(1) {
|
||||
|
||||
Reference in New Issue
Block a user