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
-
Mina Naguib September 22nd, 2007 @ 02:00 AM
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 September 22nd, 2007 @ 02:38 AM
- State changed from new to open
Thanks, that would be awesome.
-
Mina Naguib September 22nd, 2007 @ 03:59 AM
That was precisely it. Freezing 1-2-stable fixed the problem.
Thank you for a wonderful plugin. I apologize for opening the 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.
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!