Is there a way to handle "soft deletes"?
E.g set user status = DELETED
A hook that will omit DELETED users by default?
Heya! What do you mean with "omit"? Not display those in the API response?
you could add a custom field that called
deleted
and then write access control to return a query constraint like the following:
{
deleted: {
not_equals: true
}
}
that way any posts marked as deleted will still exist in the database, but will automatically be omitted from all API responses
what I mean by omit is exactly what
@364124941832159242is suggesting. Having records "deleted", never queried in the DB, but still there.
I ended up adding a
beforeOperation
hook, with something like this:
return { ...args, where: { ...args.where, status: { not_equals: UserStatus.DELETED, ...args.status } } }
Although I'm not sure how this will affect other queries 👀 . WDYT? Maybe the Access Control is more performant?
As long as you have an index on UserStatus, it will be very performant.
i would use access control instead of a
beforeOperation
hook but honestly either is the same performance. and yes, as dan said, make sure to index the field 👍
Thanks guys!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.