X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/e660e609661edadc1ed5ad49d6e83e936b2f91cd..3c1371adaf8cd9f2f67fd5e2be3b66c3fa42b56a:/lib/classic_pagination/pagination.rb?ds=inline 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,