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"]
}
}
}options
| option | type | description | required |
|---|---|---|---|
| relations | [String] | relations which you want to delete together with current model | true |
Run the tests:
npm testRun with debugging output on:
DEBUG='loopback:mixins:cascade-delete' npm test