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
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