Reputation: 15
Does anyone know how to do custom validation on array of sub model in loopback.js?
"properties": {
"rows": {
"type": [
"sub-model"
],
"required": true
}
}
Upvotes: 1
Views: 454
Reputation: 9396
In model.js
you need to add below :
function rowsValidation(err){
if(!this.rows){
err();
}
}
Model.validate('rows', rowsValidation, {message: 'Rows is not valid'});
Upvotes: 1