I think you mean recursive association? Post ->...
# orm-help
j
I think you mean recursive association? Post -> Comment -> Post
v
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
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
Thank you so much @Jarupong and @Raphael Etim. I will apply some these ideas and give it a shot.
prisma rainbow 2
r
You're welcome.
j
I'm happy to help 😃