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.

Will paginate breaks with :select and :join in mysql

#45

This is actually as much a MySQL bug as it is a will_paginate bug, but since it's easier to change will_paginate...

The following statement

Post.paginate(:select=>'posts.', 
  :joins=>"inner join forums on posts.forum_id = forums.id", 
  :page=>params[:page])

Produces the following sql
@@@SELECT count(posts.
) FROM posts@@@ which is invalid in mysql

However, if you just put

Post.paginate(:joins=>"inner join forums on posts.forum_id = forums.id", 
  :page=>params[:page])
it picks up the id from the forums table, not the posts table.

Is there a way you could add a ":select_for_count" parameter?

I suppose you could get around this by adding your own total_entries parameter, but that seems less dry than capturing it in the finder

Reported by Jeff Dean · June 23rd, 2007 @ 09:28 PM

State: new
Milestone: none
Assigned to: Chris Wanstrath Chris Wanstrath

Activity

  1. Jeff Dean
    Jeff Dean

    My bad - I didn't read the documentation well enough.

    The count parameter does exactly what I need - so in the case above (for anyone finding this) the solution is:

    Post.paginate(:select=>'posts.', 
      :joins=>"inner join forums on posts.forum_id = forums.id", 
      :page=>params[:page],
     :count=>{:select=>''})
    

    This was an invalid bug - sorry about that.

    June 23rd, 2007 @ 09:28 PM

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

    June 23rd, 2007 @ 09:28 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.