Repository navigation
Fix orphaned records being dropped when promoted to the tree root - #221
Open
payal-canyon wants to merge 1 commit into
Open
payal-canyon wants to merge 1 commit into
payal-canyon wants to merge 1 commit into
Conversation
payal-canyon
marked this pull request as ready for review
October 12, 2026 15:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a record's parent is not in the query results (for example, the parent is soft-deleted or filtered out) and
strictNullParentRootNodesis disabled,buildTreeFromResults()promotes the orphan to the root of the tree.It merges each group of children into the root using the array union operator:
Every group is a list numbered from
0, and the actual root records go through this same loop. The array union keeps the existing entry when an index already exists, so any orphan whose index is already taken is silently discarded:Example
Software: root recordHardware: root record, excluded from the results (for example, soft-deleted)Printers: child ofHardwareThe groups
[0 => Software]and[0 => Printers]are merged into[0 => Software], soPrintersis missing from the tree even though it is in the results.Fix
Append the orphaned records to the root instead of union-merging them.
Tests
Added
tests/OrphanedRecordsTest.php(with a smalltests/Fixtures/Category.phpmodel). It builds a tree through the publicquery()/getTree()API with one root record and one record whose parent is excluded from the results.Softwareis returned.vendor/bin/pest, 3 tests).Note:
run-tests.ymlcurrently only triggers formain, so the tests won't run automatically on this PR against4.x.