在 nestJs 中存在关系时找不到软删除的行



当我试图查找被软删除的行时,即使使用{with_Deleted : true},也会返回null,但当该行未被软删除时,它会返回正常值。有没有一种方法可以返回软删除的行?

联合模拟服务:

async getCorteById(id : number): Promise<ConjuntoSimulacoes>{
return await this.conjuntoSimulacoesRepository.findOne({withDeleted : true,relations : ['corte'],where : {id}});
}

congunto simulatcoes控制器:

@Get('/corte/:id')
@UseGuards(AuthGuard('jwt'))
async getCorteBySimulacao(@Param('id') id : number){
return await this.conjuntoSimulacoesService.getCorteById(id);
}

联合模拟物实体:

@ManyToOne(() => Cortes , corte => corte.conjunto_simulacoes )
corte : Cortes;

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}`);
}

相关内容