Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sailsjs delete/update multiple rows

I am working on sailsjs, I have generated api model and controller. I am just wondering if I can post and create many entries of this model instead of use curl in commandline over and over. also does this restful interface support a delete method and update method for multiple rows at once?

Thanks

like image 685
Evilsanta Avatar asked Oct 20 '22 01:10

Evilsanta


1 Answers

Most of this information is in the docs http://sailsjs.org/#/documentation/reference/blueprint-api

You can create multiple records at once in a single post by default. Post an array of entries to create.

For update and delete, I believe you will need to tweak the blueprints to look for an array of ids. Waterline, the underlying ORM of Sails supports create and delete on multiple rows, though watch out for breaking associations http://sailsjs.org/#/documentation/reference/waterline/models/update.html?q=notes

In order to override blueprints, create your own blueprints in api/blueprints/ e.g. api/blueprints/update.js and make them look for an array of ids. You'll probably want to start with the default blueprints https://github.com/balderdashy/sails/tree/master/lib/hooks/blueprints/actions.

Also, you'll need to define your own routes as the update and delete actions are by default bound to the PUT 'controller/:id' and DELETE 'controller/:id' respectively, which inherently allows for only a single id.

like image 141
leejt489 Avatar answered Oct 23 '22 23:10

leejt489