loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Cannot pass data between before save and after save

Open swfredrik opened this issue 10 years ago • 1 comments

module.exports = function(Home) {

Home.observe('before save', function (ctx, next) { console.log("before save") console.log(ctx.data.id);

Home.findById(ctx.data.id, function(err, instance){
      console.log(instance)
     ctx.hookState = instance;
     next();
})

});

Home.observe('after save', function (ctx, next) { console.log("after save") console.log(ctx.hookState) next(); }); };

My goal is to log what changes where made to the model in the after save method.

swfredrik avatar Oct 15 '16 15:10 swfredrik

Got it. http://stackoverflow.com/questions/38638637/pass-context-in-persist-to-after-save/38660028#38660028

swfredrik avatar Oct 15 '16 15:10 swfredrik