我知道the documentation of prisma-client中有一些与我的问题有关的部分:
但是,我不明白如何删除(JavaScript)pyramida-client中的所有相关记录。
例如,我的datamodel是这样的:
Add from library
如何 如何删除包含所有相关任务组,任务和任务项的电路板?!
修改:
我最近尝试了这种解决方案,它也很好用。
type Board {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "BoardOwnershipRelation")
title: String!
description: String
taskGroups: [TaskGroup!]!
}
type TaskGroup {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "TaskGroupOwnershipRelation")
board: Board!
title: String!
description: String
precedence: Int
tasks: [Task!]!
}
type Task {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "TaskOwnershipRelation")
taskGroup: TaskGroup!
title: String!
description: String
dueDate: DateTime
precedence: Int
items: [TaskItem!]!
assignedTo: [User!]! @relation(name: "AssignmentRelation")
}
type TaskItem {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "TaskItemOwnershipRelation")
task: Task!
title: String!
description: String
checked: Boolean!
precedence: Int
}
但是,有没有更好的解决方案?
答案 0 :(得分:1)
您可以使用@relation指令的“ onDelete”参数来指定删除实体(documentation)时发生的事情
您只需要像这样更改数据模型:
type Board {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "BoardOwnershipRelation")
title: String!
description: String
taskGroups: [TaskGroup!]! @relation(name: "BoardTaskGroups" onDelete: CASCADE)
}
type TaskGroup {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "TaskGroupOwnershipRelation")
board: Board! @relation(name: "BoardTaskGroups")
title: String!
description: String
precedence: Int
tasks: [Task!]! @relation(name: "TaskGroupsTask" onDelete: CASCADE)
}
type Task {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "TaskOwnershipRelation")
taskGroup: TaskGroup! @relation(name: "TaskGroupsTask")
title: String!
description: String
dueDate: DateTime
precedence: Int
items: [TaskItem!]! @relation(name: "TaskTaskItem" onDelete: CASCADE)
assignedTo: [User!]! @relation(name: "AssignmentRelation")
}
type TaskItem {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "TaskItemOwnershipRelation")
task: Task! @relation(name: "TaskTaskItem")
title: String!
description: String
checked: Boolean!
precedence: Int
}
然后删除您的董事会。所有其他删除操作将由Prisma完成