Comments (6)
Thank you for your report.
Not sure if this is something pagy can solve:
scope = User.limit(1)
scope.limit(100) # will come out with 100 records, not 1 - and pagy not involved here at all in this example
It is a known "issue" with Active Record and is the intended behaviour....but should it be?
All pagy does is basically apply limit
and offset
in the background. Not sure if it's worth the effort to solve it with pagy.
Thoughts?
from pagy.
The @users_limited returns up to Pagy::DEFAULT[:items] amount of items. Intuitively, it should return up to 2
items.
Pagy just applies the limit to whichever scope you are paginating, hence it basically reset the AR limit to the :items
variable.
I would say that 2 items would be "counter-intuitive" if you know how AR limit works.
Besides, with the last statement, you are basically stating that you want to paginate with the defined :items
, effectively overriding the scope limit. It looks quite logic to me. Did I miss anything?
from pagy.
Added warning info to the how-to docs.
@cappe I hope this will avoid any confusion.
from pagy.
@benkoshy @ddnexus Thank you for taking time to answer, and adding the warning in the docs.
I think the AR behavior for (multiple) limits makes sense. When used by the developer themselves, it's usually somewhat visible and explicit. However, when Pagy does it, it's behind the scenes. I may know that Pagy (or pagination in general) is basically limit + offset but the next person may not (especially newcomers).
hence it basically reset the AR limit to the
:items
variable.
If I use limit in my code, I should be confident it to be applied, not reset behind the scenes.
from pagy.
If I use limit in my code, I should be confident it to be applied, not reset behind the scenes.
OK. So the alternative would be ignoring the :items
if the collection is an ActiveRecord AND the collection has a set limit
.
If you want to do it automatically, it would mean checking that 2 conditions at each request, which would be an expensive performance hit without any good reason.
If you want to avoid penalizing most requests (which are practically almost the totality), then you should explicitly pass some param to the constructor, which is equivalent to just explicitly set the :items
to the limit you want, which indeed is the current behavior. 😜
from pagy.
Not too ideal either. I guess having the warning in the docs is enough. Considering use cases for using limit along with pagination isn't too common anyway. Thanks for helping sorting this out.
from pagy.
Related Issues (20)
- Add ARIA attributes to semantic helper
- Add ARIA attributes to uikit helper
- Bug: pagy_search wrong number of arguments HOT 10
- Bug: Alias for an aggregate result is removed HOT 9
- Bug: Issue with Arel scope passed to pagy method HOT 3
- Docs: 7.0 has an undocumented breaking change for active page styling HOT 5
- Docs: Which branch should PRs be made against? HOT 3
- Docs: Update performance metrics HOT 5
- Trim doesn't call with pagy_nav_js when first page is active
- Bug: Adapt with Mongoid add extention HOT 1
- Bug: Pagy::Backend#pagy_get_vars `count_args` gets ignored HOT 3
- Docs: https://ddnexus.github.io/pagy/quick-start/#configure HOT 1
- Bug: Missing initializer in documentation HOT 1
- Bug: wrong number of arguments (given 2, expected 0) HOT 2
- Bug: wrong number of arguments (given 2, expected 0) HOT 1
- Bug: Pagy not working with Geocoder gem
- Bug: Undocumented backwards-incompatible change of empty "page" parameter introduced in 6.4.0 HOT 3
- Docs: lost section about wrap existing pagination with pagy_calendar HOT 1
- Bug: Request for Pagy Gem: Making Commands Platform Independent HOT 1
- Bug: Pagy 8.4.0 is broken with MS SQL server HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pagy.