Hong
DTDrizzle Team
•Created by Hong on 1/14/2024 in #help
Question about relations
Prisma:
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime? @map("email_verified")
image String? @db.Text
accounts Account[]
sessions Session[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Comment Comment[]
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime? @map("email_verified")
image String? @db.Text
accounts Account[]
sessions Session[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Comment Comment[]
}
model Comment {
id String @id @default(cuid())
body String
user User @relation(fields: [userId], references: [id])
userId String
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Post Post @relation(fields: [postId], references: [id])
postId String
children Comment[] @relation("comment_children")
parent Comment? @relation("comment_children", fields: [parentId], references: [id], onDelete: NoAction, onUpdate: NoAction)
parentId String?
@@index([userId])
@@index([parentId])
@@index([postId])
}
model Comment {
id String @id @default(cuid())
body String
user User @relation(fields: [userId], references: [id])
userId String
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Post Post @relation(fields: [postId], references: [id])
postId String
children Comment[] @relation("comment_children")
parent Comment? @relation("comment_children", fields: [parentId], references: [id], onDelete: NoAction, onUpdate: NoAction)
parentId String?
@@index([userId])
@@index([parentId])
@@index([postId])
}
3 replies