fix: update term mutation was preventing terms from removing the parentId #3308
Merged
jasonbahl merged 4 commits intowp-graphql:developfrom Feb 12, 2025
Merged
Conversation
…as 0 or no parent. Introduces `parentDatabaseId` as an optional field for hierarchical taxonomies and notes that either parentId or parentDatabaseId should be used, but not both.
3 tasks
|
Code Climate has analyzed commit 199bde2 and detected 0 issues on this pull request. View more on Code Climate. |
|
@jasonbahl It works perfectly. |
Collaborator
Author
|
@kinnn2 thanks for confirming! Will get it released shortly 🙏🏻 |
Merged
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.
What does this implement/fix? Explain your changes.
This fixes a bug where updating child terms to have no parent was being prevented.
The bug was that we were using some
if ( empty() )checks vsif ( ! isset() )checks.So, when the ID
0was passed for the parentId, it was bailing because it was "empty", even though it was set intentionally as 0 and 0 is a valid ID to set as the parent of a term.Does this close any currently open issues?
closes: #3296
Any other comments?
Before:
Executing the updateCategory mutation on a child term, setting the parentId to
"0"would not properly set the term's parent to0, leaving the child category a child category instead of a top level category.Also, if we use an encoded id of
term:0(dGVybTow) that also does not work:After
Now, setting the
parentIdto"0"(or the encoded id forterm:0(dGVybTow)) properly updates the term to be a top-level term with no parent.Additionally, we've also added the
parentDatabaseIdinput as an option. So mutations can accept encoded Ids forparentIdor theparentDatabaseIdusing the integer value. The docs for each field have been updated to indicate one or the other should be used but not both, and an error is returned if both are used.