How do we do soft delete with prisma? busy migrati...
# orm-help
p
How do we do soft delete with prisma? busy migrating from sequelize and we got deletedAt fields and it doesnt seem like prisma is respecting those when fetching.
j
This is not currently built in - a proposal for this is at https://github.com/prisma/prisma/issues/3398
This comment specifically suggests a middleware to implement this so that you don't need to manually include it in all queries: https://github.com/prisma/prisma/issues/3398#issuecomment-688320927
p
Thanks that helps
Oh wow, I had no idea prisma.$use existed!
I can do all sorts of things with that!
prisma rainbow 2
So I could essentially do
Copy code
prisma.$use((params, next) => {
  if(params.action === 'findMany') 
    params.args['where'] = { ...params.args['where'], deletedAt: null }
  next(params)
})