Ruby on Rails
Count Limit Associations Plugin

Counting and limiting with named associations.

(NOTE: This was fixed in Rails 1.1. If you already have this plugin and are upgrading to Rails 1.1, you should remove this plugin).

Makes eager loading (using :include) work with paginate.

(NOTE: This is a pending patch, but I thought I’d offer it here as a plugin until the patch is accepted). The patch is at http://dev.rubyonrails.org/ticket/2597

Modifies ActiveRecord Model.count to allow named associations. With this plugin, you can now say:

Posts.count(:conditions => "authors.name = 'david'", :include => :authors)

When using named associations with Model.count we count the DISTINCT objects matching the conditions so that the following is true:

Posts.count(:conditions => "authors.name = 'david'", :include => :authors) == Posts.find(:conditions => "authors.name = 'david'", :include => :authors).size

This also enables paginate to work with eager loading.

@post_pages, @posts = paginate(:posts, :per_page => 10, :order => 'published_on', :include => :authors, :conditions => "authors.name = 'david'")

svn: http://jthopple.textdriven.com/svn/public/rails/plugins/count_limit_associations

See also Plugins