Skip to content

Latest commit

 

History

History
80 lines (66 loc) · 2.11 KB

README.md

File metadata and controls

80 lines (66 loc) · 2.11 KB

Build Status NSP Status

cascade-delete-mixin

This module is designed for the Strongloop Loopback framework. It provides cascade delete with a simple configuration on your models.

install

  npm install --save loopback-cascade-delete-mixin

mixinsources

Add 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"
    ]
  }
}

config

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

tests

Run the tests:

  npm test

Run with debugging output on:

  DEBUG='loopback:mixins:cascade-delete' npm test