Subqueries on joins.

In certain type of queries (filtering, reporting, etc) it is common have a subquery to select from, currently supported with from, and to join into subqueries (inline views) which is not supported.

I just ran into said situation which I had to solve by doing the subquery as a relationship and calling to_sql and then using the string form of joins.


subquery = SomeTable






OtherTable.joins(“INNER JOIN (#{subquery}) PT ON PT.ID =”)

Would it be possible to implement (or take a PR?) support for this case?

Best regards,

I have seen that use case before. I’m not sure how we could make the API to be user-friendly enough for a subquery though. I think your current implementation is good enough while still able to use ARel.


It certainly works decently with from. Can that be leveraged somehow? I am just taking a wild guess here. I haven’t really read the code very thoroughly to determine feasibility.