Fix assumption of primary key name in PredicateBuilder subquery.

This commit is contained in:
Ernie Miller
2011-08-20 13:00:26 -04:00
parent 8bd76aa50e
commit e2ae015952
2 changed files with 11 additions and 1 deletions

View File

@@ -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|

View File

@@ -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) {