some thing like:
@project = Project.find(:first)
@project.tasks.paginate :page =>2, :per_page=>2
will bring 3 sqls as:
-
this is not expected
SELECT * FROM tasks WHERE (tasks.`project_id` = 5)
SELECT count(*) AS count_all FROM tasks WHERE (tasks.project_id = 5)
SELECT * FROM tasks WHERE (tasks.project_id = 5) LIMIT 2, 2
I fit this by :
-
open vendor/plugins/will_paginate/lib/will_paginate/finder.rb
-
in "def wp_count!(options, args, finder) "
-
replace below::
if respond_to?(scoper = finder.sub(/^find/, 'with'))
send(scoper, &counter)
else
with_scope(:find => { :conditions => conditions }, &counter)
end
to :
scoper = finder.sub(/^find/, 'with')
if scoper != 'with' && respond_to?(scoper)
send(scoper, &counter)
else
with_scope(:find => { :conditions => conditions }, &counter)
end