#108 ✓resolved
RainChen

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:

  1. 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 :

  1. open vendor/plugins/will_paginate/lib/will_paginate/finder.rb
  2. in "def wp_count!(options, args, finder) "
  3. 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

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.

New-ticket Create new ticket

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!

People watching this ticket

Pages