is there a way to only connect a relation if the l...
# orm-help
t
is there a way to only connect a relation if the lookup succeeds? relevant question, if two prisma upserts are happening inside a transaction is there any way to ensure that two of them that have the same connectOrCreate don't both try to run a create (they are both runnign asyncrounously and rounded up with a promise.all)?
r
@Tyler Clendenin 👋 If two upserts are happening at the same time,
connectOrCreate
will work fine as they are executed in a transaction.
t
hrm, strange. I was getting a duplicate key error so I prefiltered all the creates and ran them first and then just used connect. that worked.
r
Could you share a small reproduction if possible?
t
i'll see if i can
`Unique constraint failed on the fields: (
name
,
type
,
userId
)`
oops, that one didn't have the transaction
and in this case when I wrap it in a transaction it seems to work, though I'm pretty sure in my actual case it still threw the errors
though I would have expected that each prisma upsert was atomic and inside it's own transaction of some sort
r
Yes it runs inside a transaction. You can see the generated SQL as well. If this is reproducible, I would suggest creating an issue here to see what’s causing this.
t
k, issue created