P
Prisma•2mo ago
Asleep

How can I disconnect a relation by using it's fields?

I need to disconnect a relation, but I cannot access the actual relation field due to the way it is setup. Let's say there is a relation called author, and I only have access to authorId, can I disconnect it by setting authorId to null/undefined?
1 Reply
RaphaelEtim
RaphaelEtim•2mo ago
Hi @Asleep 👋 To disconnect the author relation, you can set the authorId to null in your update query:
await prisma.post.update({
where: { id: 1 },
data: {
authorId: null,
},
});
await prisma.post.update({
where: { id: 1 },
data: {
authorId: null,
},
});
This will set the authorId field to null, effectively disconnecting the author relation.
Want results from more Discord servers?
Add your server