Prisma, self relation onDelete, onUpdate behavior

I have a prisma model:
model Comment {
...
children Comment[] @relation("replies")
parent Comment? @relation("replies", fields: [parentId], references: [id])
parentId String?
}
model Comment {
...
children Comment[] @relation("replies")
parent Comment? @relation("replies", fields: [parentId], references: [id])
parentId String?
}
I want to add onDelete: Cascade or onUpdate: Cascade, but it returns an error: Error validating: A self-relation must have onDelete and onUpdate referential actions set to NoAction in one of the @relation attributes. (Implicit default onDelete: SetNull, and onUpdate: Cascade) Read more at https://pris.ly/d/cyclic-referential-actions
Prisma
Special rules for referential actions in SQL Server and MongoDB
Circular references or multiple cascade paths can cause validation errors on Microsoft SQL Server and MongoDB. Since the database does not handle these situations out of the box, learn how to solve this problem.
2 Replies
Sybatron
Sybatron17mo ago
you will just have to use deleteMany when deleteting them and delete to solve that
Lopen
Lopen17mo ago
Try using sql based stuff so you can get rid of your onUpdate
Want results from more Discord servers?
Add your server