I am trying to use validate() inside my model in order to verify if the param passed in POST contains valid ID of related model. Here is the code I written inside my Person.js file:
'use strict';
module.exports = function(Person) {
Person.validate('countryId', function(err) {
var Country = Person.app.models.Country;
var countryId = this.countryId;
if (!countryId || countryId === '')
err();
else {
Country.findOne({where: {id: countryId}}, function(error, result) {
if (error || !result) {
err();
};
});
};
});
};
Person is descendent of User model and when I try to create model with other errored field (like duplicate email for example) then the response contain the error message associated with my check. Am I doing something wrong or is this a bug?