In my code, I'm dealing with an angular entity called Z
which has a property that is a list of another entity named Y
. My goal is to delete the entity Z
, but before doing so, I need to also delete all the Y
entities within it. The challenge arises from foreign key constraints in the database, which require me to delete all instances of Y
before deleting Z
.
onDelete(id: number, name: string, Y: Y[]) {
this.deleteYInZ(Y);
this.ZService.deleteZ(this.selectedSecuritySubject.value, id).subscribe(() => {
this.getAllZ();
}
}
The method deleteYInZ
looks like this:
deleteYInZ(Y: Y[]) {
for (const Yentity of Y) {
this.targetService.deleteTarget(this.selectedSecuritySubject.value, Yentity .ID).subscribe(() => {
});
}
}
I'm facing an asynchronous issue here as I tried to make the deleteYInZ
async and then used an await
in the onDelete method, but it's not functioning correctly.
Can someone guide me on how I can properly handle the deletion process by first removing all Y
entities before proceeding to remove all Z
entities?