我将几个实体保存到我的数据库中:
const tasks = taskInputs.map(task => {
this.repo.create({
name,
state,
});
})
try{
await this.repo.persist(tasks).flush();
}catch(err){
...
}
当其中一个失败时,事务失败并回滚。假设这些任务是他们失败的前 4 个任务,数据库中没有任务,但是下次我插入一个任务时,它从 id 5 开始。有没有办法从持久的 id 中删除这些任务?
我也在设置RequestContext:
app.use((_req, _res, next) => {
RequestContext.create(orm.em, next);
});