0

So I understand that the where clause in Prisma needs a unique input in order to run its delete, but I have used the @@unique function to ensure that multiple conditions need to be columns together need to be unique. What I am struggling to understand is how to implement this when it comes to the delete functionality.


model CommentDislike {
  id         Int      @id @default(autoincrement())
  comment    Comment  @relation(fields: [comment_id], references: [id], onDelete: Cascade)
  comment_id Int
  user       User     @relation(fields: [user_id], references: [id], onDelete: Cascade)
  user_id    String
  created_at DateTime @default(now())

  @@unique([user_id, comment_id])
}

 try {
      prisma.commentLike.delete({
        where: {
          user_id: user_id,
          comment_id: comment_id,
        }
      })
    } catch (e: any) {
      console.log(e)
    }

This does not work. Wanted to use the AND clause, but this does not work either.

1
  • delete() function only takes the unique id of the thing you are deleting, in this case, "id". You can either use findFirst() to find the commentLike with user and comment id and use delete() to delete it with the found id. You can also use deleteMany() to delete one field by using non unique fields Mar 13 at 17:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.