无法在 Prisma 的一个模型中建立两个 1:1 关系。检测到不明确的关系

Nik*_*yov 16 orm schema database-schema prisma prisma2

我试图在 Prisma ORM 的一个模型中建立两个 1:1 关系,但出现以下错误:

验证模型“Person”时出错:检测到不明确的关系。模型中的字段placeOfBirth和字段均指的是。请通过添加 为它们提供不同的关系名称。placeOfDeathPersonPlace@relation(<name>)

我的棱镜架构:

model Place {
    id              Int     @id @default(autoincrement())
    name            String
    persons         Person[]
}

model Person {
    id              Int     @id @default(autoincrement())
    name            String
    placeOfBirthId  Int
    placeOfDeathId  Int
  placeOfBirth    Place   @relation(fields: [placeOfBirthId], references: [id])
    placeOfDeath    Place   @relation(fields: [placeOfDeathId], references: [id])
}
Run Code Online (Sandbox Code Playgroud)

完全不明白。

ahm*_*elq 32

您必须向和添加一个name字段。然后使用这些名称在模型中引用它们。placeOfBirthplaceOfDeathPlace

model Place {
  id     Int      @id @default(autoincrement())
  name   String
  Births Person[] @relation("Births")
  Deaths Person[] @relation("Deaths")
}

model Person {
  id             Int    @id @default(autoincrement())
  name           String
  placeOfBirthId Int
  placeOfDeathId Int
  placeOfBirth   Place  @relation("Births", fields: [placeOfBirthId], references: [id])
  placeOfDeath   Place  @relation("Deaths", fields: [placeOfDeathId], references: [id])
}
Run Code Online (Sandbox Code Playgroud)