-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
This is a fork of the issue strongloop/loopback-component-push#57 and the related pull request strongloop/loopback-component-push#72 where a quick patch was created to investigate implementing a soft delete for the strongloop/loopback-component-push module.
@raymondfeng mentioned that this would make sense to generalize and bring up to the loopback level so I'm opening this issue for that.
I'd appreciate any comments from @karlmikko who mentioned here #222 (comment) implementing a soft delete via a boot script.
I'm assuming we want a field, perhaps configurable, which looks something like _is_deleted that defaults to false and is changed to true where we intend to delete. When this soft delete option is turned on for a Model the find and upsert methods likely want to filter for instances where the _is_deleted property is true.
Here's an example model definition with a possible option:
{
"name": "Customer",
"description": "A Customer model representing our customers.",
"base": "User",
"softDelete" : true
}
}And this could also allow implementers to specify the attribute name so they can match this up with data they might already have.
{
"name": "Customer",
"description": "A Customer model representing our customers.",
"base": "User",
"softDelete" : {
"attribute": "isDeleted"
}
}
}From a quick search I see a couple options:
- Use the PersistedModel setup method to wrap the
destroyAllfunctions changing from adestroyAlltoupdateAllcall passing{ _is_deleted : true } - Add a default scope to the model so our find methods all work as expected.
- Instead of default scope we could use the PersistedModel setup to wrap the find / upsert methods to filter for the soft delete attribute
Below is just for clarity, we would set the default scope programmatically, but this is what the model definition would look like with a soft delete default scope.
{
"name": "Customer",
"description": "A Customer model representing our customers.",
"base": "User",
"scope": {
"where": {
"_is_deleted": false
}
}
}I also looked at doing this from the connector level but I don't think connectors should be aware of options in the models, they are better kept simple to just implement the required CRUD methods.