I have a model with two attributes. One called userType and one called lastName.
Basically what I want to do is: if userType is professor then lastName should be required.
userType: {
type: 'string',
required: true,
enum: ['professor', 'administrator']
},
lastName: {
type: 'string',
required: function() {
return this.userType === 'professor';
}
},
Why can't I pass required as a function? In the waterline documentation there is even an example with the validation contains.
If not possible, does it have any other way to do this? I don't want to create custom validations on the controller, I want to leave everything to the model. Maybe even use the beforeValidate callback.
Thanks
required should be a boolean, not a function - try required: this.userType === 'professor' instead.