Navigation Menu

Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
patch for compatibility with polymorphic includes; should be complete…
Browse files Browse the repository at this point in the history
…ly transparent for everyone
  • Loading branch information
saizai committed Nov 2, 2009
1 parent b3b0f59 commit 1890553
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/will_paginate/finder.rb
Expand Up @@ -211,14 +211,18 @@ def wp_count(options, args, finder)
# merge the hash found in :count
# this allows you to specify :select, :order, or anything else just for the count query
count_options.update options[:count] if options[:count]


# remove polymorphic associations from the count ('cause references_eager_loaded_tables? doesn't work with e.g. polymorphic_include)
# note that polymorphic associations will still cause the main finder to error unless a plugin like polymorphic_include overrides it
count_options[:include] -= reflections.select{|x,y| y.options[:polymorphic]}.map{|x,y| x}

# forget about includes if they are irrelevant (Rails 2.1)
if count_options[:include] and
klass.private_methods.include_method?(:references_eager_loaded_tables?) and
!klass.send(:references_eager_loaded_tables?, count_options)
count_options.delete :include
end

# we may have to scope ...
counter = Proc.new { count(count_options) }

Expand Down

0 comments on commit 1890553

Please sign in to comment.