Reduce items minimum to 0 and possibly return empty array from pagy_get_items if items: 0 is specified
Code Issue
- [x] I researched through the documentation, the pagy issues and a known Search Engine, and there is no reference|report|post|video that solves this problem
- [x] I did install|upgraded to the latest version of pagy (or the latest
3.*for pagy legacy) - [x] I am providing at least one of the following working and self-contained code support that can reproduce this issue:
- [x] Simple step by step list that would work in IRB with the Pagy::Console
- [ ] Plain ruby file that can run as
ruby my-problem.rb - [ ] Edited copy of the single file pagy_standalone_app.ru
- [ ] Edited copy of the single file pagy_bare_rails.rb
- [ ] Link of my own branch forked from pagy, which contains an added test file
- [ ] Link of my own branch forked of any of the rails apps listed here.
- [ ] Link of a standalone
docker imagedownloadable from a docker repository (e.g. dockerhub.com) - [ ]
docker-composefile that can be run withdocker-compose up(and doesn't need to be built because it uses only docker images and no local context)
Ruby|Rails|Sinatra|... Versions
Ruby 3.1.2 Rails 6.1.5
Description
We would like to be able to send a items parameter of 0 and have it skip evaluating an ActiveRecord query and instead return an empty Array. If it helps, we're trying to evaluate the count of the query without getting the actual results.
While we would be happy to override the pagy_get_items method for that, the items parameter is set to a minimum of 1, so it throws a VariableError when we try this.
Steps to reproduce the issue using the provided support
Loading development environment (Rails 6.1.5)
irb(main):001:0> require 'pagy/console'
=> true
irb(main):002:0> include Pagy::Console
=> Object
irb(main):003:0> pagy_extras :items
Required extras: :items
=> nil
irb(main):004:0> pagy, items = pagy([1, 2, 3], items: 0)
Thank you!
@edeesis So, what would you need the pagy object for, if you already know that the items to paginate would be none?
If you really need a pagy object with no items, you can pass count: 0 and you will get the pagy and items set to what you are asking, and skip the query.
@edeesis Is this still an issue after my previous comment?
Hey. I'll go ahead and close this. We ended up working around it in our own way.
Thanks!