Current behavior
Consider the folowing data type:
type Folder @model {
id: ID! @unique
parent: Folder @relation(name: "FolderOnFolder", onDelete: SET_NULL)
children: [Folder!]! @relation(name: "FolderOnFolder", onDelete: CASCADE)
}
This seems reasonable. A folder will cascade its deletes _down_ the tree, but only set null up the tree.
This causes an error:
{
"data": {
"deleteFolder":null
},
"errors": [
{
"message":
"There was a loop in the path generated by the onDelete: Cascade directives on your schema when trying to do the delete.",
"locations":[],
"path":["deleteFolder"],
"code":3043,
"requestId":"api:api:cjeh2wc500055016429dfdckw"
}
]
}
Reproduction
This seems to be the case in any situation in which an object has a parent/child of its own data type.
Expected behavior?
Behavior like one would expect from a folder.
I can confirm this bug.
It seems like the recursive CASCADE is correct detected as a loop, but I don't see why that shouldn't be allowed.
+1
@marktani Any update on this?
still stucked on this
Same
Same
+1
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi,
I was facing the same issue and solved it by declaring children relation before parent relation:
# This will generate error
type Folder @model {
id: ID! @unique
parent: Folder @relation(name: "FolderOnFolder", onDelete: SET_NULL)
children: [Folder!]! @relation(name: "FolderOnFolder", onDelete: CASCADE)
}
# This wont generate error
type Folder @model {
id: ID! @unique
children: [Folder!]! @relation(name: "FolderOnFolder", onDelete: CASCADE)
parent: Folder @relation(name: "FolderOnFolder", onDelete: SET_NULL)
}
Hope it helps! :)
prisma 1.17.1
Changing the order fixed the issue for me too.
We just released an update that fixes this bug. We were also able to remove most of the restrictions around cascading deletes. So looping is not checked for anymore.
Thanks for reporting this!
Most helpful comment
still stucked on this