我正在与prisma合作,我想支持 CASCADE
删除,但是尽管我已经完成了文档中提到的所有内容,但我仍然没有让它工作
这是我尝试prisma部署时遇到的错误
Errors:
Restaurant
✖ The Mongo connector currently does not support Cascading Deletes, but the field `foods` defines cascade behavior. Please remove the onDelete argument.}
这是代码
type Restaurant {
id: ID! @id
name: String!
foods: [Food!]! @relation(onDelete: CASCADE, name: "FoodToRestaurant", link: INLINE)
}
type Food {
id: ID! @id
name: String!
desc: String
price: Float!
category: Category!
restaurant: Restaurant! @relation(name: "FoodToRestaurant", onDelete: SET_NULL)
}
我期望删除餐厅时也应删除其所有食物
我已经删除了prisma postgresql,但现在我想将mongoDB用于此应用
,但您应该手动管理它。
表示您应该递归删除所有相关实体。
例如,如果是您的DB模式:
问题 - >评论 - >费率
如果要删除问题,则应删除与该问题相关的所有评论,如果要删除评论,则应删除分配给该评论的所有费率。因此,您需要一些递归功能来删除这些实体。
function deleteQuestion(questionId) {
for each comment related to questionID
deleteComment(commentId)
delete(questionId)
}
function deleteComment(commentId) {
for each rate related to commentId
deleteRate(rateId)
delete(commentId)
}
function deleteRate(rateId) {
delete(rateId)
}
当前mongodb prisma不支持级联删除。如果您在模式中都有它。
使用参考操作,您可以为此Prisma版本3.7.0及以后的级联删除。查看参考操作的类型表https://www.prisma.io/docs/conepts/concepts/components/prisma-schema/relations/referential-actions-actions#cascade