not expected query in paginate association
Reported by RainChen | September 10th, 2007 @ 09:09 AM
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
Comments and changes to this ticket
-
Chris Wanstrath September 10th, 2007 @ 08:40 PM
- State changed from new to open
Alright, I'll check this out later today.
-
Chris Wanstrath September 28th, 2007 @ 09:31 PM
- State changed from open to resolved
Should be fixed by Mislav's latest round of changes.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Everyone's favorite Ruby library for pagination of practically anything!