【发布时间】:2019-06-27 07:54:18
【问题描述】:
我知道the documentation of prisma-client中有一些与我的问题相关的部分:
但是,我不明白如何在 (JavaScript) prisma-client 中删除一条记录及其所有相关记录。
例如,我的datamodel 是这样的:
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
}
如何删除所有相关的任务组、任务和任务项的董事会?!
编辑:
我最近尝试了这个解决方案,效果也很好。
// e.g. this is in my GraphQL resolvers async function...
await prisma.deleteManyTaskItems({
task: {
taskGroup: {
board: {
id: boardId
}
}
}
});
await prisma.deleteManyTasks({
taskGroup: {
board: {
id: boardId
}
}
});
await prisma.deleteManyTaskGroups({
board: {
id: boardId
}
});
return await prisma.deleteBoard({ id: boardId });
但是,我的问题有没有更好的解决方案???
【问题讨论】:
标签: prisma