Created
June 10, 2011 11:05
-
-
Save Hates/1018625 to your computer and use it in GitHub Desktop.
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 :ordered_by_article_count, | |
select("users.*, c.count as article_count"). | |
joins("LEFT JOIN (SELECT user_id, COUNT(user_id) as count | |
FROM articles WHERE state = 'active' GROUP BY user_id) as c ON c.user_id = users.id"). | |
where("c.count IS NOT NULL"). | |
order("c.count DESC") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment