aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-08-23 14:24:15 +0000
committerJamis Buck <jamis@37signals.com>2005-08-23 14:24:15 +0000
commitc5ff810572c7506b334f70b7036ddc7aee0257fc (patch)
tree5da1d74d9573335b16c22bf82262b3cb17b0da2f /actionpack
parentdfe1aeb776ed9a7da8b431c7933c858d155a13c7 (diff)
downloadrails-c5ff810572c7506b334f70b7036ddc7aee0257fc.tar.gz
rails-c5ff810572c7506b334f70b7036ddc7aee0257fc.tar.bz2
rails-c5ff810572c7506b334f70b7036ddc7aee0257fc.zip
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
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/pagination.rb33
2 files changed, 24 insertions, 11 deletions
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 <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 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
# <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 @@ 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)