Skip to content

Commit

Permalink
fixed; required validation for populated refs
Browse files Browse the repository at this point in the history
closes #577
  • Loading branch information
aheckmann committed Nov 2, 2011
1 parent f5dd3ae commit b99d4ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/schema/number.js
Expand Up @@ -31,8 +31,12 @@ SchemaNumber.prototype.__proto__ = SchemaType.prototype;
* @api private
*/

SchemaNumber.prototype.checkRequired = function (value) {
return typeof value == 'number' || value instanceof Number;
SchemaNumber.prototype.checkRequired = function checkRequired (value) {
if (SchemaType._isRef(this, value, true)) {
return null !== value;
} else {
return typeof value == 'number' || value instanceof Number;
}
};

/**
Expand Down
8 changes: 6 additions & 2 deletions lib/schema/objectid.js
Expand Up @@ -32,8 +32,12 @@ ObjectId.prototype.__proto__ = SchemaType.prototype;
* @api private
*/

ObjectId.prototype.checkRequired = function (value) {
return !!value && value instanceof oid;
ObjectId.prototype.checkRequired = function checkRequired (value) {
if (SchemaType._isRef(this, value, true)) {
return null !== value;
} else {
return value instanceof oid;
}
};

/**
Expand Down
8 changes: 6 additions & 2 deletions lib/schema/string.js
Expand Up @@ -115,8 +115,12 @@ SchemaString.prototype.match = function(regExp){
* @api private
*/

SchemaString.prototype.checkRequired = function (v) {
return (v instanceof String || typeof v == 'string') && v.length;
SchemaString.prototype.checkRequired = function checkRequired (value) {
if (SchemaType._isRef(this, value, true)) {
return null !== value;
} else {
return (value instanceof String || typeof value == 'string') && value.length;
}
};

/**
Expand Down

0 comments on commit b99d4ac

Please sign in to comment.