提问人:George Cosmin Taschina 提问时间:11/16/2023 更新时间:11/20/2023 访问量:33
如何在 Type 中创建具有 ID 的关系
How to create a relation with an ID inside a Type
问:
通过使用 prisma,我想在两个模型(UserWorkspace 和 Plan)之间创建关系。
我正在使用已经创建的数据库,因此我无法修改其结构。
我面临的问题是 UserWorkspace 模型有一个由包含 planId 的 Type 定义的字段,在 UserWorkspace 模型中,我想使用类型内的 ID 来定义关系。
type UserWorkspacesSubscription {
date_end DateTime? @db.Date
date_start DateTime? @db.Date
planId String? @map("plan") @db.ObjectId
}
model UserWorkspace {
id String @id @map("_id") @db.ObjectId
subscription UserWorkspacesSubscription?
Exams Exam[]
Plan Plan? @relation(fields: [subscription.planId], references: [id])
@@map("user_workspaces")
}
model Plan {
id String @id @map("_id") @db.ObjectId
UserWorkspaces UserWorkspace[]
@@map("plans")
}
但是这一行给了我一个错误:@relation(fields: [subscription.planId], references: [id])
Error validating: The argument fields must refer only to existing fields. The following fields do not exist in this model: subscription.planId
我该如何解决这个问题?
我尝试在类型中移动关系,但这对 prisma 来说不是有效的操作
答: 暂无答案
评论