loopback "after save" trigger both create and update, but I want update only

278 Views Asked by At
Product.observe('after save', function(ctx, next){
    productHelper.calProduct(ctx.instance);
    next();
  });

I have above method to do something once a product is updated, but 'after save' is also trigger by create. How can I get trigger only by update but not create?

Many thanks!

loopback": "^3.22.0" "connector": "postgresql"

2

There are 2 best solutions below

1
Ashwanth Madhav On

You can use Remote hooks.

for example:

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

where updateUser is my remote method. Change it with your method name or prototype.

0
Manson On

Finally found out that Postgresql is support isNewInstance, the problem is solved.