From c5ff810572c7506b334f70b7036ddc7aee0257fc Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Tue, 23 Aug 2005 14:24:15 +0000 Subject: Add support for :include with pagination (subject to existing constraints 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 --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_controller/pagination.rb | 33 +++++++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 62a6702ee3..140cb7e4d8 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -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 diff --git a/actionpack/lib/action_controller/pagination.rb b/actionpack/lib/action_controller/pagination.rb index 6b9294f963..a3e8f36d70 100644 --- a/actionpack/lib/action_controller/pagination.rb +++ b/actionpack/lib/action_controller/pagination.rb @@ -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 @person_pages @@ -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 ActionController :per_page => 10, :conditions => nil, :order_by => nil, + :order => nil, :join => nil, + :joins => nil, + :include => nil, :select => nil, :parameter => 'page' } @@ -102,10 +105,15 @@ module ActionController # singularizing the collection name # :per_page:: the maximum number of items to include in a # single page. Defaults to 10 - # :conditions:: optional conditions passed to Model.find_all and + # :conditions:: optional conditions passed to Model.find(:all, *params) and # Model.count - # :order_by:: optional order parameter passed to Model.find_all - # :join:: optional join parameter passed to Model.find_all + # :order:: optional order parameter passed to Model.find(:all, *params) + # :order_by:: (deprecated, used :order) optional order parameter passed to Model.find(:all, *params) + # :joins:: optional joins parameter passed to Model.find(:all, *params) + # and Model.count + # :join:: (deprecated, used :joins or :include) optional join parameter passed to Model.find(:all, *params) + # and Model.count + # :include:: 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 @@ module ActionController # 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 @@ module ActionController 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) -- cgit v1.2.3