Permalink
Browse files

Add support for :include with pagination (subject to existing constra…

…ints for :include with :limit and :offset) #1478 [michael@schubert.cx]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2041 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent dfe1aeb commit c5ff810572c7506b334f70b7036ddc7aee0257fc @jamis jamis committed Aug 23, 2005
Showing with 24 additions and 11 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +22 −11 actionpack/lib/action_controller/pagination.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Add support for :include with pagination (subject to existing constraints for :include with :limit and :offset) #1478 [michael@schubert.cx]
+
* Prevent the benchmark module from blowing up if a non-HTTP/1.1 request is processed
* Added :use_short_month option to select_month helper to show month names as abbreviations
@@ -21,7 +21,7 @@ module ActionController
# class PersonController < ApplicationController
# model :person
#
- # paginate :people, :order_by => 'last_name, first_name',
+ # paginate :people, :order => 'last_name, first_name',
# :per_page => 20
#
# # ...
@@ -37,7 +37,7 @@ module ActionController
#
# def list
# @person_pages, @people =
- # paginate :people, :order_by => 'last_name, first_name'
+ # paginate :people, :order => 'last_name, first_name'
# end
#
# Like the previous example, but explicitly creates <tt>@person_pages</tt>
@@ -48,8 +48,8 @@ module ActionController
#
# def list
# @person_pages = Paginator.new self, Person.count, 10, @params['page']
- # @people = Person.find_all nil, 'last_name, first_name',
- # @person_pages.current.to_sql
+ # @people = Person.find :all, :order => 'last_name, first_name',
+ # :conditions => @person_pages.current.to_sql
# end
#
# Explicitly creates the paginator from the previous example and uses
@@ -66,7 +66,10 @@ module Pagination
:per_page => 10,
:conditions => nil,
:order_by => nil,
+ :order => nil,
:join => nil,
+ :joins => nil,
+ :include => nil,
:select => nil,
:parameter => 'page'
}
@@ -102,10 +105,15 @@ def self.validate_options!(collection_id, options, in_action) #:nodoc:
# singularizing the collection name
# <tt>:per_page</tt>:: the maximum number of items to include in a
# single page. Defaults to 10
- # <tt>:conditions</tt>:: optional conditions passed to Model.find_all and
+ # <tt>:conditions</tt>:: optional conditions passed to Model.find(:all, *params) and
# Model.count
- # <tt>:order_by</tt>:: optional order parameter passed to Model.find_all
- # <tt>:join</tt>:: optional join parameter passed to Model.find_all
+ # <tt>:order</tt>:: optional order parameter passed to Model.find(:all, *params)
+ # <tt>:order_by</tt>:: (deprecated, used :order) optional order parameter passed to Model.find(:all, *params)
+ # <tt>:joins</tt>:: optional joins parameter passed to Model.find(:all, *params)
+ # and Model.count
+ # <tt>:join</tt>:: (deprecated, used :joins or :include) optional join parameter passed to Model.find(:all, *params)
+ # and Model.count
+ # <tt>:include</tt>:: optional eager loading parameter passed to Model.find(:all, *params)
# and Model.count
def paginate(collection_id, options={})
Pagination.validate_options!(collection_id, options, true)
@@ -159,9 +167,11 @@ def count_collection_for_pagination(model, conditions, joins)
# ordered by +options[order_by]+, for the current page in the given +paginator+.
# Override this method to implement a custom finder.
def find_collection_for_pagination(model, options, paginator)
- model.find(:all, :conditions => options[:conditions], :order => options[:order_by],
- :joins => options[:join], :select => options[:select],
- :limit => options[:per_page], :offset => paginator.current.offset)
+ model.find(:all, :conditions => options[:conditions],
+ :order => options[:order_by] || options[:order],
+ :joins => options[:join] || options[:joins], :include => options[:include],
+ :select => options[:select], :limit => options[:per_page],
+ :offset => paginator.current.offset)
end
protected :create_paginators_and_retrieve_collections,
@@ -171,7 +181,8 @@ def find_collection_for_pagination(model, options, paginator)
def paginator_and_collection_for(collection_id, options) #:nodoc:
klass = options[:class_name].constantize
page = @params[options[:parameter]]
- count = count_collection_for_pagination(klass, options[:conditions], options[:join])
+ count = count_collection_for_pagination(klass, options[:conditions],
+ options[:join] || options[:joins])
paginator = Paginator.new(self, count, options[:per_page], page)
collection = find_collection_for_pagination(klass, options, paginator)

0 comments on commit c5ff810

Please sign in to comment.