Skip to content

Conversation

goosys
Copy link
Contributor

@goosys goosys commented Sep 10, 2025

This pull request improves the stability of sorting in Administrate by introducing a tiebreaker using the primary key.

When ordering by a column, the primary key is now used as a secondary sort key to ensure stable and predictable results.
If the relation does not have a primary key, the tiebreaker is skipped.

Changes:

  • Add the primary key as a tiebreaker when ordering by a column
  • Skip the tiebreaker if the relation has no primary key
  • Update and add specs to cover these scenarios

Motivation:

Without a tiebreaker, sorting by a non-unique column can result in unpredictable order for records with the same value.
This can cause issues such as the order changing on every page load, or the same record appearing on multiple pages when paginating.
By using the primary key as a tiebreaker, we guarantee a stable sort order and prevent these problems.

Please review!

@goosys goosys force-pushed the stable-sort-with-primary-key-tiebreaker branch from bef286f to 7cd3015 Compare September 19, 2025 03:23
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

Successfully merging this pull request may close these issues.

1 participant