Browse files

only doValidate when path exists in schema

  • Loading branch information...
1 parent 82abc97 commit a19b7fcb06b6195d5ce989128f83d6be1ad4fd99 @aheckmann aheckmann committed Mar 21, 2011
Showing with 10 additions and 8 deletions.
  1. +10 −8 lib/mongoose/document.js
View
18 lib/mongoose/document.js
@@ -118,19 +118,17 @@ Document.prototype.init = function (doc, fn) {
doc[i] = {};
init(obj[i], doc[i], path + '.');
} else {
- if (schema) {
- if (obj[i] !== null && obj[i] !== undefined) {
+ if (obj[i] !== null && obj[i] !== undefined) {
+ if (schema) {
self.try(function(){
doc[i] = schema.cast(obj[i], self);
});
- }
- // mark as hydrated
- self.activePaths.init(path);
- } else {
- if (obj[i] !== null && obj[i] !== undefined) {
+ } else {
doc[i] = obj[i];
}
}
+ // mark as hydrated
+ self.activePaths.init(path);
}
}
};
@@ -377,13 +375,17 @@ Document.prototype.validate = function (next) {
if (validating[path]) return;
total++;
process.nextTick(function(){
- self.schema.path(path).doValidate(self.getValue(path), function(err){
+ var p = self.schema.path(path);
+ if (!p) return --total || next();
+
+ p.doValidate(self.getValue(path), function(err){
if (err) {
didErr = true;
return next(err);
}
--total || next();
}, self);
+
});
validating[path] = true;
}

0 comments on commit a19b7fc

Please sign in to comment.