Skip to content

Instantly share code, notes, and snippets.

Created July 12, 2012 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3098896 to your computer and use it in GitHub Desktop.
Save anonymous/3098896 to your computer and use it in GitHub Desktop.
@hot_articles = Article.all(:select => "articles.title, articles.created_at, COUNT(commentable_id) as comments_count",
:joins => "LEFT JOIN comments AS comments ON comments.commentable_id = articles.id",
:group => "comments.commentable_id",
:order => "comments_count DESC",
:limit => 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment