0
@@ -122,23 +122,13 @@ module WillPaginate::Finders
0
# Does the not-so-trivial job of finding out the total number of entries
0
# in the database. It relies on the ActiveRecord +count+ method.
0
def wp_count(options, args, finder)
0
- excludees = [:count, :order, :limit, :offset, :readonly]
0
- unless options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
0
- excludees << :select # only exclude the select param if it doesn't begin with DISTINCT
0
- # count expects (almost) the same options as find
0
- count_options = options.except *excludees
0
- # merge the hash found in :count
0
- # this allows you to specify :select, :order, or anything else just for the count query
0
- count_options.update options[:count] if options[:count]
0
+ # find out if we are in a model or an association proxy
0
+ klass = (@owner and @reflection) ? @reflection.klass : self
0
+ count_options = wp_parse_count_options(options, klass)
0
# we may have to scope ...
0
counter = Proc.new { count(count_options) }
0
- # we may be in a model or an association proxy!
0
- klass = (@owner and @reflection) ? @reflection.klass : self
0
count = if finder.index('find_') == 0 and klass.respond_to?(scoper = finder.sub('find', 'with'))
0
# scope_out adds a 'with_finder' method which acts like with_scope, if it's present
0
# then execute the count with the scoping provided by the with_finder
0
@@ -154,6 +144,23 @@ module WillPaginate::Finders
0
count.respond_to?(:length) ? count.length : count
0
+ def wp_parse_count_options(options, klass)
0
+ excludees = [:count, :order, :limit, :offset, :readonly]
0
+ unless options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
0
+ # only exclude the select param if it doesn't begin with DISTINCT
0
+ # count expects (almost) the same options as find
0
+ count_options = options.except *excludees
0
+ # merge the hash found in :count
0
+ # this allows you to specify :select, :order, or anything else just for the count query
0
+ count_options.update options[:count] if options[:count]
Comments
No one has commented yet.