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

Cursor generation for joined table columns breaks pagination #29

Open
roykillany opened this issue Aug 12, 2021 · 2 comments
Open

Cursor generation for joined table columns breaks pagination #29

roykillany opened this issue Aug 12, 2021 · 2 comments

Comments

@roykillany
Copy link

roykillany commented Aug 12, 2021

relation = Member.active.joins("LEFT JOIN memberships ON member.id = memberships.member_id")

RailsCursorPagination::Paginator.new(relation, order_by: "memberships.order", order: :desc)

generates cursors for the records w/o the distinct == or = suffixes (e.g. "W251bGwsMjYxNzRd")

im not sure if this in and of itself is an issue, but trying to use these cursors in further pagination calls always returns empty page data regardless of what combination of first/after or last/before i use.

e.g.

{:page_info=>{:has_previous_page=>true, :has_next_page=>false, :start_cursor=>nil, :end_cursor=>nil}, :page=>[]}
@roykillany
Copy link
Author

tested some more:

the following are the cursors of the first three records i get back with a simple first: 3

  1. W251bGwsMjYxNzRd
  2. W251bGwsMjYxNzNd
  3. W251bGwsMjYxNzFd

if i use first: 1 with after pointing to the 1st record, i get has_previous_page = true and has_next_page = false
if i use last: 1 with before pointing to the 2nd record, i get has_previous_page = false and has_next_page = true

similarly wonky results occur when i use other combinations

@fatkodima
Copy link

You might find this gem helpful - https://github.com/fatkodima/activerecord_cursor_paginate
I created it because I wasn't able to find solutions to this and a few other problems in existing gems.

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

No branches or pull requests

2 participants