I want to use a subquery with ActiveRecord like so:
User.select(
'users.*,
(select sum(amount)
from subscriptions
where subscriptions.user_id = user.id
and created_at < ? ) as amt)'
).order('amt')
However, on the second to last line, I have the problem that I can't figure out how to bind the Time
class parameter, as ActiveRecord::Base
's select
method doesn't accept more than one parameter (the sql string). What do I do?