关于 AfterRemove 生命周期获取id
来源:10-14 (重要)remove&delete区别:控制器&服务&存储库命名规则

weixin_慕少7054963
2025-01-19
虽然老师在afterRemove 得例子没获得id
但我尝试了
@AfterRemove()
afterRemove() {
this.logger.log(`Entity state in @AfterRemove: ${JSON.stringify(this)}`);
if (this.id) {
this.logger.log(`Removed User with id: ${this.id}`);
} else {
this.logger.warn("No id found in @AfterRemove.");
}
}
为什么这个this 打印出来没有id?
Entity state in @AfterRemove: {"logger":{"context":"User","options":{}},"username":"lyzzz","password":"32412","createdAt":"2025-01-18T22:24:54.000Z","updatedAt":"2025-01-18T22:24:54.000Z"}
是不是这个结果 在数据库中删除后 存到了内存 所以不包括id? 不太明白为什么 缺少id
写回答
1回答
-
Brian
2025-01-20
/** * Called after entity removal. */ afterRemove(event: RemoveEvent<any>) { console.log( `AFTER ENTITY WITH ID ${event.entityId} REMOVED: `, event.entity, ) }
你直接在event上来看看?
00
相似问题