Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A walkthrough of how to use the "remove" endpoint from the Blueprint API in Sails.js.

Walkthrough: Remove (Blueprint)

The example in the reference page for this blueprint endpoint on sailsjs.org assumes "rest" blueprints are enabled, and that your project contains at least an empty 'Employee' model as well as a Store model with association: employeesOfTheMonth: {collection: 'Employee'}. You'll also need at least an empty StoreController and EmployeeController. You can quickly achieve this by running:

 $ sails new foo
 $ cd foo
 $ sails generate api store
 $ sails generate api employee

...then editing api/models/Store.js:

module.exports = {
  attributes: {
   employeesOfTheMonth: {collection: 'Employee'}
  }
};

You will then need to create a store with an employeesOfTheMonth collection as described >here, e.g. with a POST payload of:

{
  "name": "Starbucks",
  "id": 16,
  "employeesOfTheMonth": [
    {
      "name": "Dolly"
    }
  ]
}

To find Dolly's id (e.g. 7):

http://localhost:1337/store/16

Then remove her from the collection: DELETE /store/16/employeesOfTheMonth/7.

Good luck!

Credits

Thanks @jodonnell-broadsoft!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.