how to delete post if it has likes
Hello lets say I have a post that i want the user to be able to delete, however the post also can have likes.
If I use something like this: prisma yells at me The change you are trying to make would violate the required relation 'LikeToPost' between the
Like
and Post
models.
How to solve that?6 Replies
pretty sure you either give some sort of cascade instruction, or just delete all the associated likes first, and then delete the post
i forget how/if cascade works in prisma
oh just reading prisma docs it seems like i need to do something like this
you can set ondelete cascade in your schema
unfortunately this is not allowed on some db providers such as planetscale
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I think it is allowed on planetscale, cascade's are just handled within the prisma client if you set relationMode to
prisma
https://www.prisma.io/docs/concepts/components/prisma-schema/relations/relation-mode#how-to-set-the-relation-mode-in-your-prisma-schema
This chart shows you what is emulated
https://www.prisma.io/docs/concepts/components/prisma-schema/relations/relation-mode#which-referential-actions-are-emulatedsorry, "not allowed" was the wrong word choice, a better wording it that its faked ("emulated by prisma client")