rails_cursor_pagination icon indicating copy to clipboard operation
rails_cursor_pagination copied to clipboard

Cursor generation for joined table columns breaks pagination

Open roykillany opened this issue 4 years ago • 2 comments
trafficstars

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 avatar Aug 12 '21 21:08 roykillany

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

roykillany avatar Aug 12 '21 21:08 roykillany

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.

fatkodima avatar Mar 08 '24 13:03 fatkodima