#193 ✓resolved
mackles

total_entries when first arg is an array

Reported by mackles | February 20th, 2008 @ 01:03 PM

I have a query that I am trying to paginate where I am passing an array of user ids. Here is a simplified example:

@rounds = Round.paginate_by_user_id(

[1,2,3],

:page => page,

:order => 'date_played desc'

)

Basically, I want to return a list of all the Round object for users 1, 2, and 3. As far as the find part, this works as expected and generates the sql with a where clause that looks like:

where user_id in (1, 2, 3)

When I call:

@rounds.total_entries

I get back 3 even though there are 50+ Round object actually returned. Digging into the will_paginate code, I found the line:

total_entries ||= (Array === args.first and args.first.size)

in:

method_missing_with_paginate

So it looks like anytime an array is passed as a first arg, the size is taken from the array. I can understand why that is being done (to support paginating arrays) but I guess there is a legit use for array args being passed to finder calls as well.

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