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
Soft delete recursive cascade #8436
Soft delete recursive cascade #8436
Conversation
I'm really against cascades further complication, but let's merge it for now, later on we need either simplify the codebase, or find a maintainer who is going to deal with constant cascade issues. |
I had to revert these changes because of failing CI. I missed few points in this PR, I'll left comments. |
.softDelete() | ||
.from(relation.inverseEntityMetadata.target) | ||
// We get back list of the affected rows primary keys for call again | ||
.returning([primaryPropertyName]) |
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.
.returning
isn't supported by all databases, for example sqlite
.
// Move throw all the relation of the subject | ||
for (const relation of subject.metadata.relations) { | ||
// Call recursive function that get the parents primary keys that in used on the inverse side in all one to many relations | ||
await this.executeSoftRemoveRecursive(relation, [Reflect.get(subject.identifier, subject.metadata.primaryColumns[0].propertyName)]); |
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.
not really clear why Reflect.get
is used here. Decorators isn't the only source of entity definitions and some people define entities using entity schemas.
The soft-delete would update recursively the related entities without loading them
related to - #8416
Description of change
The Problem
Today, the cascade soft delete update the related entities just if we would load all the entities that we want to soft-remove
This behavior is bad in term of performance and in addition, don't work recursively
Because there is no feature like that today, a lot of developers write soft delete flow for every entity that includes a lot of code because they need to kill the children as well, and that causes a lot of bugs
The Solution
Change the soft-remove flow to soft-remove all related entities recursively and automatically
I prefer to soft remove without loading all the entities and create subject to each of them because it's more efficient
Other option
Add a flag to the soft-remove function that declares that the operation should do the new logic instead of the old one
Pull-Request Checklist
master
branchnpm run lint
passes with this changenpm run test
passes with this changeFixes #0000