问题
I'm trying to add some auditing capability to my sails.js app.
The afterUpdate
lifecycle callback will give me the proper place to do what I need, but I'm hoping to avoid modifying every model to reference my new code.
Is there a way to specify an afterUpdate
callback that will fire on all models?
回答1:
Put your required overrides into config/models.js
module.exports.models = {
attributes: {},
afterUpdate: function (valuesToUpdate, cb) {
// add your logic here...
console.log('yep, updated');
cb();
},
}
The idea is that then all your models obtain this implementation of the method by default. You can also add shared attributes, as given above (currently empty object).
来源:https://stackoverflow.com/questions/34666236/can-i-specify-a-lifecycle-callback-that-fires-for-all-waterline-models-in-sails