help with prisma planetscale schema

Hello everyone, im trying to implement nested comments on my post object, this is currently my implementation without comments..
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(cuid())
title DateTime @default(now())
content String? @db.VarChar(255)
authorId String
likes Like[]
@@index([authorId])
}

model Like {
id String @id @default(cuid())
userId String
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])

}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(cuid())
title DateTime @default(now())
content String? @db.VarChar(255)
authorId String
likes Like[]
@@index([authorId])
}

model Like {
id String @id @default(cuid())
userId String
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])

}
i tried implementing it like this with the help of chatGPT
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(cuid())
title DateTime @default(now())
content String? @db.VarChar(255)
authorId String
author Like @relation(fields: [authorId], references: [id])
likes Like[]
comments Comment[]
@@index([authorId])
}

model Like {
id String @id @default(cuid())
userId String
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])
}

model Comment {
id String @id @default(cuid())
content String
authorId String
postId String
parentId String?
createdAt DateTime @default(now())
author Post @relation(fields: [authorId], references: [id])
post Post @relation(fields: [postId], references: [id])
parent Comment? @relation("CommentToComment", fields: [parentId])
children Comment[] @relation("CommentToComment")

@@relation("CommentToComment", onDelete: NoAction, onUpdate: NoAction)
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(cuid())
title DateTime @default(now())
content String? @db.VarChar(255)
authorId String
author Like @relation(fields: [authorId], references: [id])
likes Like[]
comments Comment[]
@@index([authorId])
}

model Like {
id String @id @default(cuid())
userId String
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])
}

model Comment {
id String @id @default(cuid())
content String
authorId String
postId String
parentId String?
createdAt DateTime @default(now())
author Post @relation(fields: [authorId], references: [id])
post Post @relation(fields: [postId], references: [id])
parent Comment? @relation("CommentToComment", fields: [parentId])
children Comment[] @relation("CommentToComment")

@@relation("CommentToComment", onDelete: NoAction, onUpdate: NoAction)
}
can someone help with the correct schema to model the relationship between posts and comments please?
1 Reply
m4t1box
m4t1box15mo ago
GitHub
nested-comments/server/prisma/schema.prisma at main · WebDevSimplif...
Contribute to WebDevSimplified/nested-comments development by creating an account on GitHub.
Want results from more Discord servers?
Add your server