#114 ✓resolved
Mina Naguib

Large page count when paginating an association along with deep conditions

Reported by Mina Naguib | 2007-09-21 23:19:16 UTC

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

Comments and changes to this ticket

  • Mina Naguib

    Mina Naguib 2007-09-22 02:00:51 UTC

    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.

  • Chris Wanstrath

    Chris Wanstrath 2007-09-22 02:38:23 UTC

    • State changed from “new” to “open”

    Thanks, that would be awesome.

  • Mina Naguib

    Mina Naguib 2007-09-22 03:59:02 UTC

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

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

  • Chris Wanstrath

    Chris Wanstrath 2007-09-24 00:19:45 UTC

    • State changed from “open” to “resolved”

    Cool!

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