New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

waterline-nested

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

waterline-nested

A simple helper, allows you to do nested creates and updates with Waterline 0.13 (Sails v1.0).

latest
Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Waterline Nested

A simple helper, allows you to do nested creates and updates with Waterline 0.13 (Sails v1.0).

Installation

  • Latest release
  • npm install waterline-nested

Avaliable methods

  • Nested.create(model, record)
  • Nested.createEach(model, records)
ArgumentTypeDetails
1modelStringA model name.
2recordObjectAn Object that is to be created.
2recordsArrayA list of Objects to be created.

Returns: Promise

Usage

// myApp/api/models/User.js
// A user may have many pets
module.exports = {
  attributes: {
    firstName: {
      type: 'string'
    },
    lastName: {
      type: 'string'
    },

    // Add a reference to Pets
    pets: {
      collection: 'pet',
      via: 'owner'
    }
  }
};
// myApp/api/models/Pet.js
// A pet may only belong to a single user
module.exports = {
  attributes: {
    breed: {
      type: 'string'
    },
    type: {
      type: 'string'
    },
    name: {
      type: 'string'
    },

    // Add a reference to User
    owner: {
      model: 'user'
    }
  }
};

Now that the pets and users know about each other, they can be associated. To do this we can create or update a pet with the user's object inside.

var Nested = require('waterline-nested');

Nested.create('pet', {
  breed: 'labrador',
  type: 'dog',
  name: 'fido',
  owner: { // is User model.
    firstName: {
      type: 'Dmitry'
    },
    lastName: {
      type: 'Demenchuk'
    },
  }
}).exec(function(err) {});

It will automativaly create new user and create a pet associated with that user.

TODOs

  • Add tests.
  • Find a better way to integrate waterline-nested with waterline.

Keywords

waterline

FAQs

Package last updated on 17 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts