Skip to content

fix: scope orderable join reordering by parent relation#15842

Merged
GermanJablo merged 7 commits intopayloadcms:mainfrom
GermanJablo:fix-fractional-indexing-relations-order
Mar 6, 2026
Merged

fix: scope orderable join reordering by parent relation#15842
GermanJablo merged 7 commits intopayloadcms:mainfrom
GermanJablo:fix-fractional-indexing-relations-order

Conversation

@GermanJablo
Copy link
Contributor

Context

The root problem was scope leakage in join-based ordering. Reorder operations were effectively treating join items as one shared list, so moving an item in one parent context could influence ordering in a different parent context.

Changes

  • Reorder key generation, adjacent-row lookup, and initial missing-key backfill now run in the same join on scope as the target item.
  • Fast drag/drop cases that send pending now resolve against scoped context before computing new keys.
  • index.ts keeps orchestration, and scoped query logic is extracted into focused helpers to keep behavior changes easier to review.
  • Replaced a local where-wrapper with the shared combineWhereConstraints utility.

Impact

Users can reorder join rows without cross-parent side effects. Items in unrelated parent relations no longer jump or get new keys from another parent's ordering context.

Prevent unrelated join records from influencing fractional index generation by applying the join `on` field as a scope in both default key assignment and reorder adjacency lookup. Add a regression test covering cross-parent interference for orderable join fields.
Split the orderable setup and reorder endpoint internals into focused utility functions with TSDoc so index orchestration stays minimal and easier to review, while preserving join-scope ordering behavior.
Move untouched orderable helpers back into index so the utils folder only contains logic introduced for the join-scope behavior in this PR.
Move scoped-join reorder helpers into focused utils so index.ts only keeps orchestration, making the functional root-cause changes easier to review.
Replace the orderable-specific where wrapper with Payload's shared combineWhereConstraints helper and remove the redundant local utility.
Allow orderable join scope resolution to fetch the target doc when IDs are numeric, which is required by sqlite/postgres adapters. Without this, scope detection is skipped and key generation can regress to global ordering.
@GermanJablo GermanJablo enabled auto-merge (squash) March 4, 2026 18:20
Copy link
Contributor

@DanRibbens DanRibbens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, one question came up though.

Added `req` parameter to `getJoinScopeContext` and `resolvePendingTargetKey` functions to support localized join reordering. Introduced a new test case to validate the behavior of localized join reorder keys based on request locale context. Updated the orderable field configuration to be localized, ensuring proper handling of localized data during reordering operations.
@GermanJablo GermanJablo requested a review from DanRibbens March 5, 2026 12:05
@GermanJablo GermanJablo merged commit 17a0d19 into payloadcms:main Mar 6, 2026
150 checks passed
@github-actions
Copy link
Contributor

🚀 This is included in version v3.79.1

@selvinkuik
Copy link

How can this be used in a payload.find call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants