Quote ActiveRecord::Relation with their SQL queries

This makes writing nested queries simpler, without any need for explicit
`to_sql` call. In some situations, where using `JOIN` becomes too
complicated, nested queries come in handy.

Signed-off-by: Rohan Jain <crodjer@gmail.com>