1602 / jugglingdb

Multi-database ORM for nodejs: redis, mongodb, mysql, sqlite3, postgresql, arango, in-memory...
http://1602.github.io/jugglingdb/
2.04k stars 241 forks source link

call to err() in customValidator causes failure in function validationFailed(inst, v, cb) (validations.js) #322

Closed nwaltham closed 11 years ago

nwaltham commented 11 years ago

I have written the following custom validator for jugglingdb. The code looks like this:

model.Meta.validate('key', customValidator, {message: 'Some kind of a duplicate'});
      function customValidator(err) {
          var tt=this;
          var cond = {where: {}};
          ['key','value'].map(function(attr) {
            cond.where[attr] = tt[attr];
          });
          this.constructor.all(cond, function (error, found) {
        if (error) {
            return err();
        }
        if (found.length > 1) {
            console.log("found one the same");
            err();
            } 
          });
          console.log("done");    
      };

model.Meta was created with schema.define.

When I try and save an object where the validation fails I get the following error:

TypeError: Object false has no method 'add' at onerror (/home/me/src/myproject/noduplicates/node_modules/jugglingdb/lib/validations.js:464:21) at /home/me/src/myproject/noduplicates/testCustomValidator.js:22:13

1602 commented 11 years ago

Use validateAsync instead of validate.