diff --git a/History.md b/History.md index c683bc258d4..6804dadba7c 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,19 @@ +4.2.5 / 2015-11-09 +================== + * fixed; handle setting fields in pre update hooks with exec #3549 + * upgraded; ESLint #3547 [ChristianMurphy](https://github.com/ChristianMurphy) + * fixed; bluebird unhandled rejections with cast errors and .exec #3543 + * fixed; min/max validators handling undefined #3539 + * fixed; standalone mongos connections #3537 + * fixed; call `.toObject()` when setting a single nested doc #3535 + * fixed; single nested docs now have methods #3534 + * fixed; single nested docs with .create() #3533 #3521 [tusbar](https://github.com/tusbar) + * docs; deep populate docs #3528 + * fixed; deep populate schema ref handling #3507 + * upgraded; mongodb driver -> 2.0.48 for sort overflow issue #3493 + * docs; clarify default ids for discriminators #3482 + * fixed; properly support .update(doc) #3221 + 4.2.4 / 2015-11-02 ================== * fixed; upgraded `ms` package for security vulnerability #3254 [fhemberger](https://github.com/fhemberger) diff --git a/bin/mongoose.js b/bin/mongoose.js index dde322039e0..97ba711e029 100644 --- a/bin/mongoose.js +++ b/bin/mongoose.js @@ -956,6 +956,12 @@ Document.prototype.set = function(path, val, type, options) { this.set(path[key], prefix + key, constructing); } else if (strict) { if ('real' === pathtype || 'virtual' === pathtype) { + // Check for setting single embedded schema to document (gh-3535) + if (this.schema.paths[pathName] && + this.schema.paths[pathName].$isSingleNested && + path[key] instanceof Document) { + path[key] = path[key].toObject({ virtuals: false }); + } this.set(prefix + key, path[key], constructing); } else if (pathtype === 'nested' && path[key] instanceof Document) { this.set(prefix + key, @@ -6122,6 +6128,16 @@ function Embedded(schema, path, options) { _embedded.$isSingleNested = true; _embedded.prototype.$basePath = path; + // apply methods + for (var i in schema.methods) { + _embedded.prototype[i] = schema.methods[i]; + } + + // apply statics + for (i in schema.statics) { + _embedded[i] = schema.statics[i]; + } + this.caster = _embedded; this.schema = schema; this.$isSingleNested = true; @@ -6396,7 +6412,7 @@ SchemaNumber.prototype.min = function(value, message) { msg = msg.replace(/{MIN}/, value); this.validators.push({ validator: this.minValidator = function(v) { - return v === null || v >= value; + return v == null || v >= value; }, message: msg, type: 'min', @@ -6450,7 +6466,7 @@ SchemaNumber.prototype.max = function(value, message) { msg = msg.replace(/{MAX}/, value); this.validators.push({ validator: this.maxValidator = function(v) { - return v === null || v <= value; + return v == null || v <= value; }, message: msg, type: 'max', @@ -9639,9 +9655,9 @@ EmbeddedDocument.prototype.constructor = EmbeddedDocument; */ EmbeddedDocument.prototype.markModified = function(path) { + this.$__.activePaths.modify(path); if (!this.__parentArray) return; - this.$__.activePaths.modify(path); if (this.isNew) { // Mark the WHOLE parent array as modified // if this is a new document (i.e., we are initializing diff --git a/package.json b/package.json index cce61bc378e..d3c080e53e8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mongoose", "description": "Mongoose MongoDB ODM", - "version": "4.2.5-pre", + "version": "4.2.5", "author": "Guillermo Rauch ", "keywords": [ "mongodb",