我想创建一个模式,在该模式中,实体Chapter
具有也是Chapter
的子项。
它必须是一对多的关系,因为一个章节可以有多个子节点,但只能有一个父节点。
我发现很难在我的Prisma模式中定义它。我尝试了一些方法,但总是显示错误:
// children and parent fields
model Chapter {
id Int @default(autoincrement()) @id
// ...
children Chapter[] @relation("children")
parent Chapter? @relation(fields: [parentId], references: [id])
parentId Int?
}
// children field whith @relation
model Chapter {
id Int @default(autoincrement()) @id
// ...
children Chapter[] @relation("children")
}
// just children as an array of Chapter
model Chapter {
id Int @default(autoincrement()) @id
// ...
children Chapter[]
}
// Only parent (I could work with that)
model Chapter {
id Int @default(autoincrement()) @id
// ...
parent Chapter? @relation(fields: [parentId], references: [id])
parentId Int?
}
有什么想法吗?
发布于 2021-08-19 07:10:07
这就是我们要走的路。一对多关系,其中一个父项可以有多个章节:
model Chapter {
id Int @id @default(autoincrement())
children Chapter[] @relation("children")
parent Chapter? @relation("children", fields: [parentId], references: [id])
parentId Int? @map("chapterId")
}
https://stackoverflow.com/questions/68841406
复制相似问题