Implementing soft delete

I would like to implement a mechanism similar to soft deletes, in which objects are not really deleted from the database, they instead become not available for querying / retrieval and only marked as deleted. In a regular database this could be achieved with a view, or maybe implemented directly in a regular backend API implementation the condition on IsDeleted = false would be added when querying objects in repository code.

What would be the reasonable way to implement this feature in Parse?

One is to of course use a regular Boolean field like IsDeleted and add the condition on each and every query, but there are two problems I see here. First, it’s easy to forget it. Second - anyone would be able to see the deleted objects by simply running their own query without that condition, outside of my app.

Second option would be to use an ACL, possibly with a beforeSave trigger on the IsDeleted flag, that would set the read permission on the object accordingly, e.g.:

"*": { 
    "read": false 
},
"role:admins": {
    "read": true,
    "write": true
}

If I understand correctly, removing the read permission from the general public would work here, and only users authenticated and authorized as admin role members would then be able to see these records.

Since I’m very new to Parse, I might be missing something, I would appreciate any feedback.

Cheers,
Marcin

Soft delete can be achieved with a before save hook function. On isDeleted dirty key, you can create a new Parse.ACL() and set public write and read to false. Then your object will be only accessible with master key :slight_smile:

You can also keep some roles (like Admin) on the object to allow admins to access to deleted rows

Basically exactly what I described? Great, that gives me confidence in going forward with the idea, thanks!

1 Like