nestjs - 在 typeorm 中有关系时找不到软删除的行-nestJs
问题描述
当我试图找到一个被软删除的行时,即使有,也会{with_Deleted : true}
返回 null ,但是当该行没有被软删除时,它会返回正常。有没有办法可以返回软删除的行?
conjunto-simulacoes 服务:
async getCorteById(id : number): Promise<ConjuntoSimulacoes>{
return await this.conjuntoSimulacoesRepository.findOne({withDeleted : true,relations : ['corte'],where : {id}});
}
conjunto-simulacoes 控制器:
@Get('/corte/:id')
@UseGuards(AuthGuard('jwt'))
async getCorteBySimulacao(@Param('id') id : number){
return await this.conjuntoSimulacoesService.getCorteById(id);
}
conjunto-simulacoes 实体:
@ManyToOne(() => Cortes , corte => corte.conjunto_simulacoes )
corte : Cortes;
科尔特斯实体:
@OneToMany(() => ConjuntoSimulacoes , conjunto_simulacoes => conjunto_simulacoes.corte )
conjunto_simulacoes : ConjuntoSimulacoes[]
解决方案
我修复了做一个新查询,在我的最后一个查询中{with_Deleted : true}
是在表内conjunto simulacoes
而不是在表中搜索cortes
。
新查询:
async getCorteByIdWithDeleted(id : number){
return await this.conjuntoSimulacoesRepository.query(`SELECT * FROM conjunto_simulacoes
as conjunto LEFT JOIN cortes as corte on corte.id = conjunto."corteId"
WHERE conjunto.id=${id}`);
}
推荐阅读
- c - 用于套接字客户端通信的每个线程的状态机
- angular - 如何在角度 6 中为选择选项设置默认选定对象
- elasticsearch - Elasticsearch helm chart pod 卡在“Init:CrashLoopBackOff”状态
- amazon-dynamodb - AppSync BatchDeleteItem not executes properly
- c# - 遍历任务列表 C#
- c - 将字符串从 .csv 文件转换为双精度
- sql - 如何在 SQL Server 中获取特定作业中的表列表
- javascript - 加载特定的网址并自动点击按钮
- mongodb - 无法查询嵌套文档的 _id(其他字段有效)
- scala - Spark过滤掉列并使用剩余列创建dataFrame并使用过滤列创建dataFrame