I have two models: Group & GroupMember
I would like to return Groups, sorted by the highest GroupMember Count? How do you setup this type of join/query count in Rails?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Life is so much easier with counter_cache:
Only one query, only on the groups table.
edit
If you need to reset the group_members_count:
(because reset_counters doesn’t take an array of ids)
In future Rails 3.2.0, you will write:
I can’t wait 😉