Reputation: 56
I'm trying to make a CLI application using prisma.
In my schema.prisma
file I have a Folder
and Phew
table to make the "filesystem"
I want to delete all sub-folders and phews when a parent is deleted.
I tried to "Cascade" but it throws an error
Error validating: A self-relation must have
onDelete
andonUpdate
referential actions set toNoAction
in one of the @relation attributes. Read more at https://pris.ly/d/cyclic-referential-actions
Here is the Folder
schema:
model Folder {
folder_id String @id @default(auto()) @map("_id") @db.ObjectId
name String
readonly Boolean @default(false)
private Boolean @default(true)
// relations
user_id String @db.ObjectId
user User @relation(fields: [user_id], references: [user_id], onDelete: Cascade)
phews Phew[]
Folders Folder[] @relation(name: "parent")
parent Folder? @relation(name: "parent", fields: [parent_folder_id], references: [folder_id], onDelete: NoAction, onUpdate: NoAction)
parent_folder_id String? @db.ObjectId
// timestamps
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
I read this docs but I didn't find a way to solve this.
Upvotes: 4
Views: 376