0
在发生验证之后,我想在将模型保存到数据库之前更新模型。Strongloop回送验证和请求生命周期
什么是回环请求生命周期中的正确点(呃哦,这开始让我想起.NET webforms!)来做到这一点?
Report.validatesPresenceOf('basicInfo');
Report.beforeRemote('create', addCreatorId);
function addCreatorId(ctx, instance, next) {
// alter the model, validation has not occurred yet
}
Report.observe('before save', sendToThirdParty);
function sendToThirdParty(ctx, instance, next) {
// send contents to third party, alter model with response
// validation has not occurred yet
}
Report.afterRemote('create', sendEmail);
function sendEmail(ctx, record, next) {
// model has been saved to the database
// validation occurs before this point
}
理想我想默认的回送模型验证触发被称为addCreatorId
和sendToThirdParty
功能之前。我应该怎么做呢?
我可以在我的before save
钩子中明确地呼叫model.isValid()
,但似乎我应该能够重新排列这些以便自动发生。
回送Operation Hooks文档在验证发生时没有提及,也没有提到Remote Hooks文档。