我可以指定为sails.js 中的所有水线模型触发的生命周期回调吗 [英] Can I specify a lifecycle callback that fires for all waterline models in sails.js

查看:41
本文介绍了我可以指定为sails.js 中的所有水线模型触发的生命周期回调吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的sails.js 应用程序添加一些审计功能.afterUpdate 生命周期回调会给我一个合适的地方来做我需要的事情,但我希望避免修改每个模型来引用我的新代码.

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.

有没有办法指定将在所有模型上触发的 afterUpdate 回调?

Is there a way to specify an afterUpdate callback that will fire on all models?

推荐答案

将您需要的覆盖放入 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).

这篇关于我可以指定为sails.js 中的所有水线模型触发的生命周期回调吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆