2.0.0 • Published 6 years ago

loopback-cascade-delete-mixin v2.0.0

Weekly downloads
428
License
MIT
Repository
github
Last release
6 years ago

Build Status NSP Status

cascade-delete-mixin

Greenkeeper badge

IMPORTANT! Mixin object structure is changed. If you use "relationsConfig" key, please use 1.3.1 version
npm install --save loopback-cascade-delete-mixin@1.3.1 
or change object structure! (see below)

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

Node.js v. > 6

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": ""
        },
        "description": {
           "type": "hasMany",
           "model": "Property",
           "foreignKey": ""
         }
     },
    "mixins": {
      "CascadeDelete": {
        "relations": 
        ["properties",
        {"name": "description", "deepDelete": false}],
        "deepDelete": true,
      }
    }
  }

options

optiontypedescriptionrequired
relationsString or Objectrelations which you want to delete together with current model, see object keys belowtrue
deepDeleteBooleanenable 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 mattersfalse

relations object

keytypedescriptionrequired
nameStringrelation nametrue
deepDeleteBooleanenable or disable the deep delete function for current relation. 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 mattersfalse
foreignKeyStringcustom foreign keyfalse

tests

Run the tests:

  npm test

Run with debugging output on:

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