loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Loopback Custom Validation Throws Error

Open x0cipher opened this issue 11 years ago • 2 comments

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

x0cipher avatar Jun 25 '15 04:06 x0cipher

I think you need Connection.validateAsync instead.

fabien avatar Jun 25 '15 04:06 fabien

Thanks. This helped. One query though, why does simple Validatable.validate() not work in this case ?

x0cipher avatar Jun 26 '15 12:06 x0cipher