【发布时间】:2022-07-11 20:45:00
【问题描述】:
我有 2 个用户和联系人模型 一旦用户被删除,我想要的表之间就没有连接,那么用它创建的相同的联系人姓名也将被删除
我在 SignUp 中所做的操作会同时添加一个新联系人和一个新用户,但是 在删除中我不知道如何捕捉它们,因为它们没有相互连接。
添加工作好(添加联系人和用户):
signUp(){
this.usersService.Register(this.signupForm.value)
.subscribe(() => {
this.contactsService.AddContact(this.signupForm.value)
.subscribe(() => {
this.swal.success();
this.signupForm.reset();
this.router.navigate(['login']);
})
},(e)=> {
this.errorsService.errors(e);
})
}
删除:(无效):
this.contactsService.DeleteContact(contact.id)
.subscribe(() =>{
this.router.navigate(['login']);
})
this.usersService.DeleteUser(user.id)
.subscribe(()=>{
this.router.navigate(['login']);
})
}
在删除过程中,他只删除了用户而不是联系人,因为导航是根据用户的 id 完成的
【问题讨论】:
-
您应该在联系人模型中添加一个可索引的“userId”字段,因此每当您使用用户删除时,您也可以找到删除联系人的信息。
-
这是我做不到的问题,模型不应该互相认识
-
为什么?如果是这样,您不能将这两个信息都保存在另一个模型中,然后改用它吗?
-
因为是微服务
标签: angular