ActiveRecord::Relation where clauses hash syntax accepts an ActiveRecord::Relation as a value, but it maps the relation to ids when it could just use a subquery. By converting the Relation to an ast we can now accept any subquery.
Model.where(:id => AnotherModel.some_scope.select(:some_id))
will only run one query and it supports references to tables from the outer query.
Have corresponded with @tenderlove on this.
removed an unnecessary second query when passing an ActiveRecord::Rel…
…ation to a where clause. And added ability to use subselects in where clauses.
Merged to master and pushed. Thanks.