Sailsjs: Beforeupdate (lifecycle Callback), Access Current Values
It's clear how to access the new values, the first argument contains them beforeUpdate: function (values, cb) {....} But how can I access the current values, that are to be replace
Solution 1:
In order do access current values you will have to make the call and get the current record.
models/user.jsbeforeCreate: function (values, cb) {
User.findOne(this.update.arguments[0].id || this.update.arguments[0]).exec(err, function(originalUser){/*...*/})
}
Also check out https://github.com/balderdashy/waterline/issues/1004#issuecomment-102432862 , where this issue is being discussed. Should provide insight into getting the ID and a current solution.
The solution above was updated to reflect the comments.
Post a Comment for "Sailsjs: Beforeupdate (lifecycle Callback), Access Current Values"