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
I have written the following custom validator for jugglingdb. The code looks like this:
model.Meta was created with schema.define.
When I try and save an object where the validation fails I get the following error: