loopback
loopback copied to clipboard
Loopback Custom Validation Throws Error
While using Validatable.validate() the Custom function is throwing an internal loopback error.
var duplicateConnection = function(err, done, er) {
Connection.find({where: {userId: this.userId, nucleusId: this.nucleusId}},
function(bug, connection) {
if (!_.isEmpty(connection)) {err();}
});
};
Connection.validate("userId", duplicateConnection);
Error
if (kind !== false) inst.errors.add(attr, message, code);
^
TypeError: undefined is not a function
at \node_modules\loopback-datasource-juggler\lib\validations.js:550:37
I think you need Connection.validateAsync instead.
Thanks. This helped. One query though, why does simple Validatable.validate() not work in this case ?