“保存后环回”会触发创建和更新,但我只想更新

问题描述 投票:0回答:2
Product.observe('after save', function(ctx, next){
    productHelper.calProduct(ctx.instance);
    next();
  });

我有上述方法,一旦产品更新后就可以执行某些操作,但是创建后也会触发“保存后”。如何仅通过更新而不是通过创建来触发?

非常感谢!

loopback“:” ^ 3.22.0““ connector”:“ postgresql”

postgresql loopback after-save
2个回答
0
投票

您可以使用Remote hooks

例如:

Product.afterRemote('updateUser', (ctx, userRes, next) => { next() {...code ....} })

其中updateUser是我的远程方法。用您的方法名称或原型进行更改。


0
投票

最后发现Postgresql是支持isNewInstance的,此问题已解决。

© www.soinside.com 2019 - 2024. All rights reserved.