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.

Large page count when paginating an association along with deep conditions

#114

Example:

@author.articles.paginate(:all, :include => :comments, :conditions => "comments.approved = true", :page => params[:page])

Will issue an errant "count" sql that does not include a "FROM" clause or proper condition for the inner-most "comments" association. Under postgresql:

  • The DB notices that the condition references "comments.*" so it happily reports "NOTICE: adding missing FROM-clause entry for table "comments""
  • The resulted count is absurdly large since all comments were multiplied by the left query instead of being explicitly scoped by comments.article_id = articles.id
  • Causing .page_count to be extremely large

Reported by Mina Naguib · September 21st, 2007 @ 11:19 PM

State: resolved
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Mina Naguib
    Mina Naguib

    After a bit of research, I believe that this is already handled by test "test_paginate_associations_with_include" which recommends upgrading to rais > 1.2.3 to obtain http://dev.rubyonrails.org/chang...

    I'll try to follow the recommendation without breaking things and will report back on whether it's the same thing and it worked or this is still an outstanding bug, in which case I'll prepare a failing test case.

    September 22nd, 2007 @ 02:00 AM

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

    Thanks, that would be awesome.

    September 22nd, 2007 @ 02:38 AM

  3. Mina Naguib
    Mina Naguib

    That was precisely it. Freezing 1-2-stable fixed the problem.

    Thank you for a wonderful plugin. I apologize for opening the ticket.

    September 22nd, 2007 @ 03:59 AM

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

    Cool!

    September 24th, 2007 @ 12:19 AM

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.