javascript - Get current values inside Sails' Waterline beforeUpdate hook -
in sails' waternline need able compare previous value new 1 , assign new attribute under condition. example:
beforeupdate: function(newvalues, callback) { if(/* currentvalues */.age > newvalues.age) { newvalues.permission = false; } }
how access currentvalues
?
i'm not sure best solution can current record doing simple findone
request:
beforeupdate: function(newvalues, callback) { model .findone(newvalues.id) .exec(function (err, currentvalues) { // handle errors // ... if(currentvalues.age > newvalues.age) { newvalues.permission = false; } return callback(); }); }
Comments
Post a Comment