I have an angular entity Z which one of its properties is a list of another entity Y, I need to delete entity Z and when I do it I need to delete the list of entity Y inside of it. The problem is that first I need to delete all the Y values and then delete the Z due to FK problems on database. My method is the following:
onDelete(id: number, name: string, Y: Y[]) {
this.deleteYInZ(Y);
this.ZService.deleteZ(this.selectedSecuritySubject.value, id).subscribe(() => {
this.getAllZ();
}
}
and the deleteYInZ is:
deleteYInZ(Y: Y[]) {
for (const Yentity of Y) {
this.targetService.deleteTarget(this.selectedSecuritySubject.value, Yentity .ID).subscribe(() => {
});
}
}
I have an async problem here I tried to do async deleteYInZ and then put an await on the onDelete method but It's not working
How can I do to first delete all the Y and after it finishes delete all the Z?