In Sails' Waternline I need to be able to compare the previous value with the new one and assign a new attribute under some condition. For example:
beforeUpdate: function(newValues, callback) {
if(/* currentValues */.age > newValues.age) {
newValues.permission = false;
}
}
How could I access the currentValues
?
I'm not sure this is the best solution but you can get the current record by doing a 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();
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With