0
确实TypeORM包括一些functionnality避免这种情况:TypeORM UPSERT - 创建如果不存在
let contraption = await thingRepository.findOne({ name : "Contraption"});
if(!contraption) // Create if not exist
{
let newThing = new Thing();
newThing.name = "Contraption"
await thingRepository.save(newThing);
contraption = newThing;
}
喜欢的东西:
let contraption = await thingRepository.upsert({name : "Contraption"});