Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

not expected query in paginate association

#108

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

Reported by RainChen · September 10th, 2007 @ 09:09 AM

State: resolved
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Chris Wanstrath
    Chris Wanstrath
    • State changed from new to open

    Alright, I'll check this out later today.

    September 10th, 2007 @ 08:40 PM

  2. Chris Wanstrath
    Chris Wanstrath
    • State changed from open to resolved

    Should be fixed by Mislav's latest round of changes.

    September 28th, 2007 @ 09:31 PM

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.