Skip to content

Commit

Permalink
Fixed pagination to work with joins #1034 [scott@sigkill.org]
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1159 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Apr 13, 2005
1 parent 7f558cb commit ad24c6d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Fixed pagination to work with joins #1034 [scott@sigkill.org]

* Fixed that *rest parameter in map.connect couldn't accept an empty list #1037 [Dee.Zsombor@gmail.com]

* Added :confirm option to link_to_remote just like link_to has #1082 [yrashk@fp.org.ua]
Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_controller/pagination.rb
Expand Up @@ -150,8 +150,8 @@ def create_paginators_and_retrieve_collections #:nodoc:
# Returns the total number of items in the collection to be paginated for
# the +model+ and given +conditions+. Override this method to implement a
# custom counter.
def count_collection_for_pagination(model, conditions)
model.count(conditions)
def count_collection_for_pagination(model, conditions, joins)
model.count(conditions,joins)
end

# Returns a collection of items for the given +model+ and +conditions+,
Expand All @@ -168,7 +168,7 @@ def find_collection_for_pagination(model, conditions, order_by, join, 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])
count = count_collection_for_pagination(klass, options[:conditions], options[:join])

paginator = Paginator.new(self, count, options[:per_page], page)

Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -415,7 +415,7 @@ def delete_all(conditions = nil)
# Returns the number of records that meets the +conditions+. Zero is returned if no records match. Example:
# Product.count "sales > 1"
def count(conditions = nil, joins = nil)
tbl_var_name = joins ? table_name[0,1].downcase : ""
tbl_var_name = joins ? table_name[0,1].downcase : ""
sql = "SELECT COUNT(*) FROM #{table_name} #{tbl_var_name} "
sql << ", #{joins} " if joins
add_conditions!(sql, conditions)
Expand Down

0 comments on commit ad24c6d

Please sign in to comment.