Skip to content

devpascoe/loopback-cascade-delete-mixin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Delete related models

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%