Creating deeply nested Prisma entries

I am trying to create a deeply nested object in Prsima using explicit many to many and it sort of works? The problem is, it seems Prisma has 0 proper error handling at anything more than 1 level deep. For example if I have
prisma.portfolio.create({
data: {
locations: {
create: input.locations?.map((location) => ({
Location: {
connectOrCreate: {
where: { name: location?.name }
create: {
name: location?.name
contacts: {
connectOrCreate: location.contacts?.map((contact) => {
where: {
name: contact.name
}
create: {
name: "Some invalid value"
}
}
}
}
}
},
})),
},
});
prisma.portfolio.create({
data: {
locations: {
create: input.locations?.map((location) => ({
Location: {
connectOrCreate: {
where: { name: location?.name }
create: {
name: location?.name
contacts: {
connectOrCreate: location.contacts?.map((contact) => {
where: {
name: contact.name
}
create: {
name: "Some invalid value"
}
}
}
}
}
},
})),
},
});
Then, I will get an error on trying to post this but the error is something extremely inaccurate like Location is not a valid key on locations did you mean "Name"? However when I then remove the invalid key from the contacts, the code works just fine. So the problem is obviously the contact field but I get no information about what field is actually incorrect or why. Is there a way to deal with this? Right now my first thought is to possibly break out each nested create into its own separate call but I don't feel like that is right.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server