lib/active_scaffold/finder.rb in active_scaffold-3.3.1 vs lib/active_scaffold/finder.rb in active_scaffold-3.3.2
- old
+ new
@@ -342,11 +342,11 @@
options = find_options.reject{|k,v| [:select, :reorder].include? k}
options[:includes] = count_includes
# NOTE: we must use :include in the count query, because some conditions may reference other tables
count_query = append_to_query(beginning_of_chain, options)
- count = count_query.count
+ count = count_query.count(:distinct => true)
# Converts count to an integer if ActiveRecord returned an OrderedHash
# that happens when find_options contains a :group key
count = count.length if count.is_a? ActiveSupport::OrderedHash
count
@@ -365,9 +365,10 @@
if options[:pagination] && options[:pagination] != :infinite
count = count_items(find_options, options[:count_includes])
end
klass = beginning_of_chain
+ klass = klass.uniq if find_options[:outer_joins].present?
# we build the paginator differently for method- and sql-based sorting
if options[:sorting] and options[:sorting].sorts_by_method?
pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page|
sorted_collection = sort_collection_by_column(append_to_query(klass, find_options).all, *options[:sorting].first)
sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination]