Loopback "loaded" 操作挂钩未被调用
Loopback "loaded" operation hook not being called
环回 "loaded" 操作挂钩未被调用。
Post.observe('loaded', function logQuery(ctx, next) {
console.log('In loaded');
console.log('CTX %s', JSON.stringify(ctx));
next();
});
对于 "access" 它工作正常,
Post.observe('access', function logQuery(ctx, next) {
console.log('Accessing %s matching %s', ctx.Model.modelName, ctx.query.where);
console.log('Accessing matching %s', JSON.stringify(ctx));
next();
});
如果我在 "loaded" 钩子
中遗漏了什么,请告诉我
这取决于您如何使用该模型。文档指出 loaded
仅适用于以下内置方法:
- 查找()
- findOne()
- findById()
- 存在()
- 计数()
- 创建()
- 更新插入()
(与 updateOrCreate() 相同)
- findOrCreate()*
- prototype.save()
- prototype.updateAttributes()
来源:https://docs.strongloop.com/display/public/LB/Operation+hooks#Operationhooks-loaded
我不是过度依赖环回文档的人,因为他们经常遗漏一些关键信息……但这可能提供了一个原因。
这是关于 access
挂钩的内容:
The access hook is triggered whenever a database is queried for models, that is when any create, retrieve, update, and delete method of PersistedModel is called.
所以我认为您需要检查您在这些模型上测试代码所使用的方法。
环回 "loaded" 操作挂钩未被调用。
Post.observe('loaded', function logQuery(ctx, next) {
console.log('In loaded');
console.log('CTX %s', JSON.stringify(ctx));
next();
});
对于 "access" 它工作正常,
Post.observe('access', function logQuery(ctx, next) {
console.log('Accessing %s matching %s', ctx.Model.modelName, ctx.query.where);
console.log('Accessing matching %s', JSON.stringify(ctx));
next();
});
如果我在 "loaded" 钩子
中遗漏了什么,请告诉我这取决于您如何使用该模型。文档指出 loaded
仅适用于以下内置方法:
- 查找()
- findOne()
- findById()
- 存在()
- 计数()
- 创建()
- 更新插入() (与 updateOrCreate() 相同)
- findOrCreate()*
- prototype.save()
- prototype.updateAttributes()
来源:https://docs.strongloop.com/display/public/LB/Operation+hooks#Operationhooks-loaded
我不是过度依赖环回文档的人,因为他们经常遗漏一些关键信息……但这可能提供了一个原因。
这是关于 access
挂钩的内容:
The access hook is triggered whenever a database is queried for models, that is when any create, retrieve, update, and delete method of PersistedModel is called.
所以我认为您需要检查您在这些模型上测试代码所使用的方法。