Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array doesn't get paginated when total count is passed in #1110

Open
janko opened this issue Sep 5, 2023 · 1 comment
Open

Array doesn't get paginated when total count is passed in #1110

janko opened this issue Sep 5, 2023 · 1 comment

Comments

@janko
Copy link

janko commented Sep 5, 2023

Here is the example that demonstrates my scenario:

require "kaminari"

paginated_array = Kaminari.paginate_array([*1..200], total_count: 1000).page(8)
paginated_array.size #=> 200

I expected the size of the array to be 25 (default per page), holding only numbers 176..200.

My use case is that I'm paginating over two SQL tables, so my strategy was to retrieve the first page * per_page records from each table, sort them and paginate that collection in memory. Since the in-memory array doesn't hold the possible records that can be retrieved from the DB, I wanted to pass in total_count so that the last page button in the view works as expected.

@yuki24
Copy link
Member

yuki24 commented Feb 5, 2024

There was a historical reason why this is designed this way - #516. So changing this behaviour for this specific, possibly less common, use case would introduce a breaking change for other, possibly more common, use case.

In my experience, merging data from multiple tables has always been tricky to get right, and I personally wouldn't recommend that. For RDB, I think this should probably be handled at the DB-level features, such as SQL View or CTE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants