loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Model hook "before save" is executed before validateAsync is finished

Open mackwan84 opened this issue 10 years ago • 2 comments

I have define validateAsync methods for my model and found that Model hook "before save" is executed even though my model validation (async) return false. In my opinion, it should be an issue, right?

mackwan84 avatar Dec 10 '15 04:12 mackwan84

hi @mackwan84, would you be able to provide steps to reproduce your issue? Report Bug

Because validateAsync runs asynchronously, I believe you would have to validate the model before the operational hook methods if you need to use validateAsync

Model.beforeSave = function(cb, modelInstance){
  modelInstance.isValid( function( isValidResult ){
    cb();
  }
}

davidcheung avatar Dec 10 '15 21:12 davidcheung

Cleaning up stale issues, please reopen if this issue still persist, thanks!

davidcheung avatar Jun 14 '16 21:06 davidcheung