-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add tree entities update and delete logic #7156
feat: add tree entities update and delete logic #7156
Conversation
Allows tree entities relations to be updated and deleted via the save function from the Repository Closes: typeorm#7155
Mssql uses a conventional delete to manage the junction table Allow TreeParent onDelete CASCANDE on all drivers except mssql, mssql will throw an error saying that the feature is not supported.
I got
This is how I create and save a new folder.
Error at line 70 typeorm/src/persistence/tree/ClosureSubjectExecutor.ts Lines 67 to 73 in 1358dfb
And if I check undefined its works normally
|
@boydaihungst |
@boydaihungst |
@mateussilva92
|
@boydaihungst |
@mateussilva92 |
@boydaihungst |
@pleerock Thank you! |
Hi @mateussilva92, thanks for doing this! I've been using it for a few weeks in production with success. There is one issue however: Setting a parent property to
Setting the |
Actually, I am not sure about my previous comment. I did get this error message, but not consistently :-/ What would be the expected workflow for fixing faulty tree table states? For example, the closure table state and the actual parent relations can diverge, either because of bugs like the mentioned one or when you edited the tables manually – now they're out of sync. Would a |
Hey @phil294 thanks for the good catch and for the awesome feedback along side the repo to help visualize the bug. |
let metadata: EntityMetadata | undefined = undefined; | ||
try { | ||
metadata = this.connection.getMetadata(table.name); | ||
} catch (err) { } // Ignore error and continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try ...catch
can be replaced with hasMetadata(table.name)
condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch, fixed.
thank you for contribution! |
This edit removes the note which links to the closed issue typeorm#2032, that is supposed to be fixed in this PR typeorm#7156 .
Allows tree entities relations to be updated and deleted via the save function from the Repository
Closes: #7155
Description of change
Main changes are done to main
SubjectExecutor.ts
and all the tree executors.I added logic to all the tree executors to allow tree relation changes via the update function and also added the delete logic to
NestedSetSubjectExecutor.ts
.On the
SubjectExecutor.ts
the biggest change done was to run the nested set updates in series instead of parallel just like all the other entities updates are done. The reason for that is explained in #7155.Enable onDelete option for TreeParent in all RDBMS except for mssql.
Also cascade delete for closure junction table is also enabled to all RDBMS and as custom code to add the same behaviour in mssql.
All the other file changes are either small format changes, code cleanup or some changes that allow the main new feature to work.
Fixes #193
Fixes #2032
Fixes #2418
Fixes #3691
Fixes #3988
Fixes #4174
Fixes #4353
Fixes #5268
Fixes #6118
Duplicated by #3556
Note:
The development also prevents the creation of more than one root entity for nested sets I'm not sure if that's an approach that you would like to have or not.
Pull-Request Checklist
master
branchnpm run lint
passes with this changenpm run test
passes with this changeFixes #0000