Since `createMany` doesn't allow us to create the ...
# orm-help
m
Since
createMany
doesn't allow us to create the relations. What I'm doing is to first call
createMany
for the "base" write, and then I get the recently created ids with
findMany
and then call
createMany
again for each of the relations. The problem with this is that if some of the relations fail, the previous writes still exists. So I need to manually delete them in this case, and even this is not perfect, because while one of the elements on the createMany may have failed, not all of them would. I was planning on using a transaction but I saw that it doesn't help me in this case. What would be the best practice to do this then? Manually loop through each record and use nested write instead, and not do batches with createMany? But then it'd take a looong time instead. Is there a different solution?
a
you may be able to do that with interactive transactions in Prisma, which you have to enable in preview mode.
m
Sorry, was in a meeting. Will take a look at those. Thank you!
But if it wasn't for this feature, the other option would be to loop and create records individually instead of batching?
a
I guess so? Then you have the guarantee of the nested relations being inserted with the parent, but that's MUCH slower if you're doing a batch of, say, 500 records or something. Like, dozens or hundreds of times slower.