无法在 Prisma 的一个模型中建立两个 1:1 关系。检测到不明确的关系
Can't make two 1:1 relations in one model in Prisma. Ambiguous relation detected
我试图在 Prisma ORM 的一个模型中建立两个 1:1 关系,但出现以下错误:
Error validating model "Person": Ambiguous relation detected. The fields placeOfBirth
and placeOfDeath
in model Person
both refer to Place
. Please provide different relation names for them by adding @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])
}
完全不明白
您必须向 placeOfBirth
和 placeOfDeath
添加一个 name
字段。然后使用这些名称在 Place
模型中引用它们。
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])
}
我试图在 Prisma ORM 的一个模型中建立两个 1:1 关系,但出现以下错误:
Error validating model "Person": Ambiguous relation detected. The fields
placeOfBirth
andplaceOfDeath
in modelPerson
both refer toPlace
. Please provide different relation names for them by adding@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])
}
完全不明白
您必须向 placeOfBirth
和 placeOfDeath
添加一个 name
字段。然后使用这些名称在 Place
模型中引用它们。
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])
}