This module is designed for the Strongloop Loopback framework. It provides cascade delete with a simple configuration on your models.
npm install --save loopback-cascade-delete-mixinAdd the mixins property to your server/model-config.json like the following:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-cascade-delete-mixin",
"../common/mixins"
]
}
}To use with your Models add the mixins attribute to the definition object of your model config.
{
"name": "Product",
"properties": {
"name": {
"type": "string",
}
},
"relations": {
"properties": {
"type": "hasMany",
"model": "Property",
"foreignKey": ""
}
},
"mixins": {
"CascadeDelete": {
"relations": ["properties", "description"],
"deepDelete": true
}
}
}options
| option | type | description | required |
|---|---|---|---|
| relations | [String] | relations which you want to delete together with current model | true |
| deepDelete | [Boolean] | enable or disable the deep delete function. If activated, the CascadeDelete will be executed on the deleted related models as well (if they have the CascadeDelete mixin specified). If not used, disable it for performance matters | false |
Run the tests:
npm testRun with debugging output on:
DEBUG='loopback:mixins:cascade-delete' npm test