Nested set treeRootNode option - fix tricky and improve performance#3045
Open
wilfi00 wants to merge 2 commits intodoctrine-extensions:mainfrom
Open
Nested set treeRootNode option - fix tricky and improve performance#3045wilfi00 wants to merge 2 commits intodoctrine-extensions:mainfrom
wilfi00 wants to merge 2 commits intodoctrine-extensions:mainfrom
Conversation
Nested set changes in recover method : * refactor code * fix tricky comparison with the treeRootNode option * slighly better performance when using treeRootNodeOption
Author
|
Could I have an answer to this, please? Thanks 🙏 |
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.
Hello!
I came across a "bug" when using the
recovermethod with thetreeRootNodeoption:In
NestedTreeRepository, the code loops through each root node and compares the current node with the one provided in the options. However, comparing objects can be tricky in PHP, and in my case, it wasn't working.My root node is a Doctrine entity. When I pass this node as an option, it has a fully instantiated
Userattribute. ButgetRootNodes()returns an entity with a lazy-loadedUserobject. Because of this, the comparison was wrongly returning false.The attribute of the root node I give in option:

The attribute of the root node being iterated by

NestedTreeRepository:I suggest a refactor to unify the logic whether it's a forest, a specific root node, or a single tree. This way, we avoid the direct object comparison entirely, and it works like a charm.
I am not very familiar with this type of contribution, so feel free to request changes or ask questions 🙏
edit: I've also updated the
verifymethod to apply the same logic.Thank you,
Johan