Last active
December 24, 2015 13:09
-
-
Save autumn-hoerr/6802903 to your computer and use it in GitHub Desktop.
order a model by the number of an associated records it has
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope :order_by_activities, joins(:activities).select('users.id, users.name, count(activities) as total_activities').group('users.id').order('total_activities desc') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment