Issue
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?
Solution
If you really want a fast way of doing it, put a counter_cache
on a users' solutions (have a solutions_count
column in your User
) and order by that column. You don't need to manage that counter, because rails does it for you. You can read more about counter_cache
in the Rails Guides
Answered By - Andrei S Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.