A User has_many Solutions
How do I order Users by those with the most Solutions?
I'm trying to find the top ten users but I'm not sure how the most tidy or efficient way to do this?
Does anyone have an example that isn't too computationally expensive?
User
.joins(:solutions)
.select("users.*, count(solutions.id) as scount")
.group("users.id")
.order("scount DESC")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With