Martin Ratinaud
Posted on August 28, 2023
I've been using Prisma on my latest project Karaoke Tools and as crazy as it may seem, I did not find any easy way (like a plugin) to handle soft delete behaviour.
So I had to tweak it myself manually and ending up in a case where
-
deletedAt
can be null -
deletedAt
can NOT exist
This is because I'm using mongo and no default value for deletedAt
.
This filtering in Prisma is not handled by default (like deletedAt: null
so I had to do it with an OR
request.
const items = await prisma.event.findMany({
...
where: filters: {
OR: [{ deletedAt: { isSet: false } }, { deletedAt: null }],
...
});
As it took me almost an hour to find this (chatGPT not being helpful), I wrote this article.
Cheers
💖 💪 🙅 🚩
Martin Ratinaud
Posted on August 28, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined 🚀 Building a Comprehensive Job Portal with Next.js, ShadcnUI, Prisma & MongodB, and Google Generative AI
August 18, 2024