如何在prisma graphql中设置递归列



所以我有一个注释模型,我想添加一个与注释模型类型相同的回复列。我该如何实现它?

model Comment {
@@map("comments")
uuid          String      @default(uuid()) @id
createdAt     DateTime    @default(now())
updatedAt     DateTime    @updatedAt
body          String      @db.VarChar(255)
user          User        @relation(fields: [userUuid], references: [uuid])
userUuid      String
post          Post        @relation(fields: [postUuid], references: [uuid])
postUuid      String
up            Upvote[]
down          Downvote[]
upvoteCount   Int         @default(0)
downvoteCount Int         @default(0)
}

由于一个注释可以有许多嵌套的注释,因此它将形成一个1-many的自关系。所以像这样的东西应该起作用:

model Comment {
uuid          String    @id @default(uuid())
createdAt     DateTime  @default(now())
updatedAt     DateTime  @updatedAt
body          String
upvoteCount   Int       @default(0)
downvoteCount Int       @default(0)
comments      Comment[] @relation("CommentToComment")
comment     Comment? @relation("CommentToComment", fields: [commentUuid], references: [uuid])
commentUuid String?
@@map("comments")
}

最新更新