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