mislav / will_paginate

Pagination library for Rails and other Ruby applications
http://github.com/mislav/will_paginate/wikis
MIT License
5.71k stars 864 forks source link

Re pagination sequel query #639

Closed triplepointfive closed 1 year ago

triplepointfive commented 1 year ago

In sequel, I have a long scope with pagination in it, like:

scope = User.where(id: ids1).paginate(page, size)

Later on, I need to filter it more and recall paginate since it cached the total count with the previous result. Without will_paginate I can do it like

scope = scope.where(id: ids2).limit(nil).paginate(page, size)

But with the gem installed, it fails with

ArgumentError: wrong number of arguments (given 1, expected 0)

will_paginate-3.3.1/lib/will_paginate/sequel.rb:33:in `offset'

Ideas

This method should probably respect calling with an argument: https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/sequel.rb#L33

Or calling paginate resets limits & offset by itself

Or adding remove_pagination method to remove the limit & offset

mislav commented 1 year ago

Later on, I need to filter it more and recall paginate since it cached the total count with the previous result.

Hi, it would be helpful to share the entire snippet of logic you're trying to do, including the version of Sequel you're using. But just by reading your description, one thing that stands out to me is that you need to re-paginate the same scope that you've already paginated, and I don't think that would work. Is it an option for you to create a whole new scope from scratch?

triplepointfive commented 1 year ago

sequel version 5.53.0

Yes, I can fix it differently, including re implementing original scope. My point is calling paginate twice shouldn't fail with such error ArgumentError: wrong number of arguments (given 1, expected 0)

mislav commented 1 year ago

Thanks for reporting, but I would say that calling paginate on an already paginated collection isn't supported and that the workaround would be to restrict your app to call paginate on a scope only once.