#45 ✓invalid
Jeff Dean

Will paginate breaks with :select and :join in mysql

Reported by Jeff Dean | 2007-06-23 21:28:38 UTC

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

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 ยป

Shared Ticket Bins

People watching this ticket

Referenced by

Pages