Error handling deeply nested writes

This post https://github.com/prisma/prisma/issues/8776 goes into pretty good detail about the issue. I'm just wondering if anyone here has a good solution for this? I have a large form to submit and on submission I have a lot of related data that gets created all at once in my database. I can't have it return an error saying unknown arg. I can't do form validation with a useless error like that. My current thought is to maybe create the new item and then update each of the related fields in separate calls to potentially get an error from each of those. Something like:
#This does not work
await prisma.user.create({
data: {
....,
post: {
connect: { id: post_id }
}
}
}

#Potential solution
const user = await prisma.user.create({
data: {
....,
}
}

await prisma.user.update({
where: {
id: user.id
},
post: {
connect: { id: post_id }
}
})
#This does not work
await prisma.user.create({
data: {
....,
post: {
connect: { id: post_id }
}
}
}

#Potential solution
const user = await prisma.user.create({
data: {
....,
}
}

await prisma.user.update({
where: {
id: user.id
},
post: {
connect: { id: post_id }
}
})
This feels really dumb though.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server