X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ca8e1bf18822e77acda9437c9980d5359894a502..640ff57465b5288a183e1343285c1550b1a0d1a8:/lib/classic_pagination/pagination.rb diff --git a/lib/classic_pagination/pagination.rb b/lib/classic_pagination/pagination.rb index 6a3e1a97b..fa1307bee 100644 --- a/lib/classic_pagination/pagination.rb +++ b/lib/classic_pagination/pagination.rb @@ -173,21 +173,34 @@ module ActionController # the +model+ and given +conditions+. Override this method to implement a # custom counter. def count_collection_for_pagination(model, options) - model.count(:conditions => options[:conditions], - :joins => options[:join] || options[:joins], - :include => options[:include], - :select => (options[:group] ? "DISTINCT #{options[:group]}" : options[:count])) + collection = model.joins(options[:join] || options[:joins]) + collection = collection.where(options[:conditions]) + collection = collection.includes(options[:include]) + + if options[:group] + collection = collection.select(options[:group]).distinct + elsif options[:count] + collection = collection.select(options[:count]) + end + + collection.count end # Returns a collection of items for the given +model+ and +options[conditions]+, # ordered by +options[order]+, 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] || options[:order], - :joins => options[:join] || options[:joins], :include => options[:include], - :select => options[:select], :limit => options[:per_page], - :group => options[:group], :offset => paginator.current.offset) + collection = model.joins(options[:join] || options[:joins]) + collection = collection.where(options[:conditions]) + collection = collection.order(options[:order_by] || options[:order]) + collection = collection.includes(options[:include]) + collection = collection.group(options[:group]) + + if options[:select] + collection = collection.select(options[:select]) + end + + collection.offset(paginator.current.offset).limit(options[:per_page]) end protected :create_paginators_and_retrieve_collections,