LearnBoost/mongoose — Issue #577: using DBRef together with required validator breaks
Author: Swatinem
Created: 2011-10-25 12:01:29+00:00
State: open

When changing the definition of BlogPost in model.ref.test.js to:

var BlogPost = new Schema({
_creator : { type: ObjectId, ref: 'RefUser', required: true }
, title : String
, comments : [Comment]
, fans : [{ type: ObjectId, ref: 'RefUser' }]
});

(note the required: true)

breaks all the tests with the following error:

{"stack":"ValidationError: Validator \"required\" failed for path _creator\n at Model.invalidate (/mongoose/lib/document.js:605:29)\n at /mongoose/lib/document.js:585:16\n at validate (/mongoose/lib/schematype.js:275:7)\n at /mongoose/lib/schematype.js:292:9\n at Array.forEach (native)\n at ObjectId.doValidate (/mongoose/lib/schematype.js:280:19)\n at Array. (/mongoose/lib/document.js:583:9)\n at EventEmitter._tickCallback (node.js:126:26)","message":"Validation failed","name":"ValidationError","errors":{"_creator":{"stack":"Validator \"required\" failed for path _creator\n at validate (/mongoose/lib/schematype.js:275:10)\n at /mongoose/lib/schematype.js:292:9\n at Array.forEach (native)\n at ObjectId.doValidate (/mongoose/lib/schematype.js:280:19)\n at Array. (/mongoose/lib/document.js:583:9)\n at EventEmitter._tickCallback (node.js:126:26)","message":"Validator \"required\" failed for path _creator","name":"ValidatorError","path":"_creator","type":"required"}}}