Search code examples
node.jssails.jswaterline

Sailsjs Model.update not working in controller


Just a quick beginner question...

Are controllers allowed to perform updates in Sails? I know the action routes do, however I can not get code like this to update.

//controller code (this DOES NOT update)

Packets.update({packet:5},{cron:'locationhistory'})
.then( function(r){
        console.log(r);
    });

This process works, so I'm confused why the above will not.

//controller code that does work, however I'm calling a custom function
sails.models.packets.updateMyPacket('locationhistory', 9, function( response ){
        console.log(response);
    });

// model code
updateMyPacket: function( p, num, cb) {
Packets.update({ cron: p}, {packet: num}).then( function( packets){
    cb(packets);
});

}

Can anybody help? What am I missing?

thanks Matt


Solution

  • In your example you have your Criteria and your Values swapped between the two different approaches.