Skip to content

fullcube/loopback-ds-cascade-update-mixin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CASCADE UPDATE MIXIN

Greenkeeper badge

CircleCI Dependencies Coverage Status

This module is designed for the Strongloop Loopback framework. It provides cascade update functionality with a simple configuration on your models. This can be used to keep property values synchronised across related models.

INSTALL

  npm install --save loopback-ds-cascade-update-mixin

SERVER CONFIG

Add the mixins property to your server/model-config.json:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "../node_modules/loopback-ds-cascade-update-mixin/lib",
      "../common/mixins"
    ]
  }
}

CONFIG

To use with your Models add the mixins attribute to the definition object of your model config.

The config keys are the property names that you want to cascade.

The config values are an array of relationships that the property updates should cascade to.

  {
    "name": "Product",
    "properties": {
      "name": {
        "type": "string",
      }
    },
    "relations": {
        "relation1": {
          "type": "hasMany",
          "model": "Property",
          "foreignKey": ""
        }
     },
    "mixins": {
      "CascadeUpdate": {
         "status": [ "relation1", "relation2" ],
         "isTest": [ "relation1", "relation2" "relation3" ]
       }
    }
  }

TESTING

Run the tests in test.js

  npm test

DEBUGGING

Run with debugging output on:

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