Update Multiple records at once using Waterline

755 views
Skip to first unread message

Testers

unread,
Nov 20, 2014, 6:27:02 AM11/20/14
to sai...@googlegroups.com

So I'm making this app where I will have menu items for a restaurant right ?

The owner should have the ability to move around the menu items

This is my menuitem.js Model contains

name , price , position

That's it. Super simple.

So to reposition these elements I will use jquery UI So the final product will be something very similar to this > http://jqueryui.com/sortable/

So my goal is to save the position of each of these menu items on the database every time one of the menu items has been changed. So I thought Sails must have a function that can update all records at once

Like below

Menuitem.update([{id: 1},{position: 3}], [{id: 2},{position: 3}] ).exec(function(err, updatedRecords) {
            if (err) {
                return res.send({message: 'Could not update the records', err: err}, 500);
            }

            if (updatedRecords) {
                return res.send({ records: updatedRecords }, 200);
            } else {
                return res.notFound('Records not found');
            }
        });

Any help would be greatly appreciated

Also opened an issue on SailsJS https://github.com/balderdashy/sails/issues/2404

Reply all
Reply to author
Forward
0 new messages