Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
Created August 20, 2008 20:58
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 duncanbeevers/6447 to your computer and use it in GitHub Desktop.
Save duncanbeevers/6447 to your computer and use it in GitHub Desktop.
class Article < ActiveRecord::Base
named_scope :with_total_articles_published,
:select => 'articles.*, COUNT(*) AS total_articles_published',
:group => 'user_id'
end
Article.with_total_articles_published.each do |aggregate_article|
puts "User #{aggregate_article.user_id} has published" \
" #{pluralize(aggregate_article.total_articles_published, 'article')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment