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文檔。