https://www.prisma.io/ logo
#orm-help
Title
# orm-help
j

Jarupong

09/29/2022, 11:56 AM
I think you mean recursive association? Post -> Comment -> Post
v

ven v

09/29/2022, 11:56 AM
model Comment { id Int @id @default(autoincrement()) title String @default("Untitled") content String @default("") hashtags String[] @default([]) // author author User @relation(fields: [authorId], references: [authId]) authorId String // replies - replyToId Int? @default(autoincrement()) replyTo Comment? @relation("replies", fields: [replyToId], references: [id], onDelete: NoAction, onUpdate: NoAction) replies Comment[] @relation("replies") // media files mediaFiles MediaFile[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } model MediaFile { id Int @id @default(autoincrement()) url String providerPublicId String? key String? // user user User @relation(fields: [userId], references: [authId]) userId String // comments comment Comment? @relation(fields: [commentId], references: [id]) commentId Int? @default(autoincrement()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt }
will this work?
i would like something optimal from a search perspective
yes @Jarupong. recursive. i have given it a first shot but not convinced my schema is optimal or even right.
According to my experience, I think your schema is very simple
But you should have at least 3 tables to cover all cases
let say Post -> Comment -> Reply -> Post
It will be kind of circular deps
r

Raphael Etim

09/29/2022, 12:20 PM
This article effectively captures the modelling of this system. You might want to read through and then write out the Prisma models for it.
v

ven v

09/29/2022, 12:25 PM
Thank you so much @Jarupong and @Raphael Etim. I will apply some these ideas and give it a shot.
prisma rainbow 2
r

Raphael Etim

09/29/2022, 12:25 PM
You're welcome.
j

Jarupong

09/29/2022, 12:27 PM
I'm happy to help 😃
3 Views