#114 ✓resolved
Mina Naguib

Large page count when paginating an association along with deep conditions

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

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

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