Closed roscom closed 3 years ago
Hey @roscom, it looks like you've encountered a bug in Scuttle. If I recall correctly, Scuttle used to handle nested subqueries like this correctly, but something has probably changed in recent versions of activerecord/arel. I played around in the console for a while and got it to work. The key is using an arel table and the project
method when constructing the subquery:
Post.arel_table[:domain_id].in(
Domain.arel_table.project(:id).where(
Domain.arel_table[:role_id].eq(Role.arel_table[:id])
)
)
Hope that helps :)
I have the sql worked out and it works correctly in practice. Using scuttle to convert to Arel format introduces a problem. It would appear that the correlated table in the subquery does not reference the outer query. My schema looks like this:
The working sql with subquery highlighted:
The generated Arel "equivalent", again with the correlated sub query highlighted
resulting in:
ActiveRecord::StatementInvalid (Mysql2::Error: Unknown column 'roles.id' in 'where clause')
which refers to the correlated subquery.Would you be able to point me in the right direction regards this? ~ Ross