Fix cursor-based pagination with lexicographic ordering for composite fields (#12467)

# Fix cursor-based pagination with lexicographic ordering for composite
fields

## Bug

The existing cursor-based pagination implementation had a bug when
handling composite fields.
When paginating through results sorted by composite fields (like
`fullName` with sub-properties `firstName` and`lastName`), the WHERE
conditions generated for cursor positioning were incorrect, leading to
records being skipped.

The previous implementation was generating wrong WHERE conditions:

For example, when paginating with a cursor like `{ firstName: 'John',
lastName: 'Doe' }`, it would generate:

```sql
WHERE firstName > 'John' AND lastName > 'Doe'
```

This is incorrect because it would miss records like `{ firstName:
'John', lastName: 'Smith' }` which should be included in forward
pagination.

## Fix

Create a new util to use proper lexicographic order when sorting a
composite field.

---------

Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Raphaël Bosi
2025-06-11 16:48:03 +02:00
committed by GitHub
parent 4cea354838
commit d4995ab54e
15 changed files with 1710 additions and 183 deletions

View File

@ -2,5 +2,6 @@ export const TEST_PERSON_1_ID = '777a8457-eb2d-40ac-a707-551b615b6980';
export const TEST_PERSON_2_ID = '777a8457-eb2d-40ac-a707-551b615b6981';
export const TEST_PERSON_3_ID = '777a8457-eb2d-40ac-a707-551b615b6982';
export const TEST_PERSON_4_ID = '777a8457-eb2d-40ac-a707-551b615b6983';
export const TEST_PERSON_5_ID = '777a8457-eb2d-40ac-a707-551b615b6984';
export const NOT_EXISTING_TEST_PERSON_ID =
'777a8457-eb2d-40ac-a707-551b615b6990';