model Comment {
id Int @id @default(autoincrement())
content String @db.MediumText
replyId Int?
reply Comment? @relation(name: "ReplyComments", fields: [replyId], references: [id],onDelete: NoAction, onUpdate: NoAction)
comments Comment[] @relation(name: "ReplyComments")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
postId Int
hearts CommentHeart[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([userId])
@@index([postId])
@@index([replyId])
}
It works well in creating or editing a comment and a reply. but if I delete a parent comment including a reply, it wouldn't delete the parent comment before removing the reply. So, how do I do?? I mean I would like to work if I delete a parent comment, the comment will delete with any reply using 'on delete: Cascade'.
So, my solution is before deleting a parent comment, I send a query removing children replies. So, I don't like to send two queries. Just I want to send only one query.