Add primary key tiebreaker for stable sorting - #2886
Conversation
bef286f to
7cd3015
Compare
|
Oh, fun! Could you add something to the docs on this as well? |
0bd8a6b to
9d728cc
Compare
|
I've added the docs! How does this look? |
|
By the way, do you think the tiebreak logic should live inside |
nickcharlton
left a comment
There was a problem hiding this comment.
Thanks! The docs look good to me. I just have a preference for capitalising the keywords on SQL statements!
|
|
||
| ```sql | ||
| -- When toggling the name attribute | ||
| select * from users order by name desc, id desc; |
There was a problem hiding this comment.
| select * from users order by name desc, id desc; | |
| SELECT * FROM users ORDER BY name DESC, id DESC; |
| select * from users order by name desc, id desc; | ||
|
|
||
| -- When toggling the name attribute again | ||
| select * from users order by name asc, id asc; |
There was a problem hiding this comment.
| select * from users order by name asc, id asc; | |
| SELECT * FROM users ORDER BY name ASC, id ASC; |
|
|
||
| ```sql | ||
| -- When toggling the name attribute | ||
| select * from users order by name desc; |
There was a problem hiding this comment.
| select * from users order by name desc; | |
| SELECT * FROM users ORDER BY name DESC; |
|
@pablobm, do you have any thoughts on this one? I think you might've spent more time in this part of the code base than I have. |
9d728cc to
be1cf4d
Compare
|
Always tricky with these things, but... this looks good to me 🙂 The one thing I'm not sure is if the guides is the right place to put this documentation. In my mind the guides is a place to put "recipes" that require configuration or code, while here we are just explaining how the UI works. Having said that, I don't know what a good place would be 🤔 Thoughts? |
|
Crazy idea, re: where to put this documentation - Perhaps it should be a comment in the controller template. Similar to the existing ones. Perhaps we should add comments for Just a thought! Not 100% convinced myself. |
|
Thank you for your comment! I've previously read comments from everyone wanting to enrich the documentation, so I'm keen to write more in the |
|
@goosys - Sounds good 🙂 I think it makes sense to create a new doc under |
be1cf4d to
1ebc6ce
Compare
1ebc6ce to
d35f964
Compare

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:
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!