I'd like to order a model query result by the sum of multiple has_many associations. For example, a User query method that orders results based on his/her total count of (comments + answers + votes). These are all models that belong to User.
I use a User instance method, children, to lump together these associations already, but I'm having trouble getting ActiveRecord's order method to order by children.count.
I want this to work (but it doesn't):
User.all.order("#{children.count} DESC")
How would one do this?