0
我想知道是否以及如何在Sails中做下面的事情。基本上,我試圖處理複雜的驗證 - 我有一個客戶端模型和ContactPerson模型。客戶端模型中嵌入了ContactPersons,我想在繼續之前驗證它們都是正確的。如何創建模型的實例並驗證它,而無需在Sails中保存到數據庫?
// client.js
module.exports = {
attributes: {
name: {
type: 'string',
required: true
}
},
beforeValidation: function(values, cb) {
values.contactPerson.forEach(function(person) {
var contactPerson = new sails.model.person(person);
var results = contactPerson.validate();
// If valid, continue
// if not valid, invalidate the client Model (cause validationerror)
});
}
}