【发布时间】:2016-01-14 22:17:16
【问题描述】:
我正在研究类似于Can I specify a lifecycle callback that fires for all waterline models in sails? 的东西。
我希望能够在回调中引用模型定义,但当前只有属性和 id 被发送到 afterUpdate。除了添加“类型”作为属性之外,有没有办法确定我正在使用的模型?
【问题讨论】:
我正在研究类似于Can I specify a lifecycle callback that fires for all waterline models in sails? 的东西。
我希望能够在回调中引用模型定义,但当前只有属性和 id 被发送到 afterUpdate。除了添加“类型”作为属性之外,有没有办法确定我正在使用的模型?
【问题讨论】:
正确的范围加上 this 将在 config/models.js 中工作。
module.exports.models = {
attributes: { . . .},
afterUpdate: function (model) {
console.log(this.identity); //model name that triggered callback
console.log(this.definition); //model definition
//logic . . .
}
};
【讨论】: