rails/rails — pull request #15947 by ncolgan (2014-06-27 21:21:29+00:00)
Title: PredicateBuilder should use in rather than eq for Arel::SelectManager

When using `where` against an arel subquery, ActiveRecord::Relation::PredicateBuilder matches the subquery to the attribute using `Arel::Predications#eq`, rather than `Arel::Predications#in`. We should be using `in` instead.

The statement

Author.where(id: Book.arel_table.project(:author_id))

currently generates the sql

SELECT \"authors\".* FROM \"authors\" WHERE \"authors\".\"id\" = (SELECT author_id FROM \"books\")

which results in a postgres error if the subquery returns more than one row.

It should generate

SELECT \"authors\".* FROM \"authors\" WHERE \"authors\".\"id\" IN (SELECT author_id FROM \"books\")

instead.