@@ -956,6 +956,12 @@ Document.prototype.set = function(path, val, type, options) {
956
956
this.set(path[key], prefix + key, constructing);
957
957
} else if (strict) {
958
958
if ('real' === pathtype || 'virtual' === pathtype) {
959
+ // Check for setting single embedded schema to document (gh-3535)
960
+ if (this.schema.paths[pathName] &&
961
+ this.schema.paths[pathName].$isSingleNested &&
962
+ path[key] instanceof Document) {
963
+ path[key] = path[key].toObject({ virtuals: false });
964
+ }
959
965
this.set(prefix + key, path[key], constructing);
960
966
} else if (pathtype === 'nested' && path[key] instanceof Document) {
961
967
this.set(prefix + key,
@@ -6122,6 +6128,16 @@ function Embedded(schema, path, options) {
6122
6128
_embedded.$isSingleNested = true;
6123
6129
_embedded.prototype.$basePath = path;
6124
6130
6131
+ // apply methods
6132
+ for (var i in schema.methods) {
6133
+ _embedded.prototype[i] = schema.methods[i];
6134
+ }
6135
+
6136
+ // apply statics
6137
+ for (i in schema.statics) {
6138
+ _embedded[i] = schema.statics[i];
6139
+ }
6140
+
6125
6141
this.caster = _embedded;
6126
6142
this.schema = schema;
6127
6143
this.$isSingleNested = true;
@@ -6396,7 +6412,7 @@ SchemaNumber.prototype.min = function(value, message) {
6396
6412
msg = msg.replace(/{MIN}/, value);
6397
6413
this.validators.push({
6398
6414
validator: this.minValidator = function(v) {
6399
- return v === null || v >= value;
6415
+ return v == null || v >= value;
6400
6416
},
6401
6417
message: msg,
6402
6418
type: 'min',
@@ -6450,7 +6466,7 @@ SchemaNumber.prototype.max = function(value, message) {
6450
6466
msg = msg.replace(/{MAX}/, value);
6451
6467
this.validators.push({
6452
6468
validator: this.maxValidator = function(v) {
6453
- return v === null || v <= value;
6469
+ return v == null || v <= value;
6454
6470
},
6455
6471
message: msg,
6456
6472
type: 'max',
@@ -9639,9 +9655,9 @@ EmbeddedDocument.prototype.constructor = EmbeddedDocument;
9639
9655
*/
9640
9656
9641
9657
EmbeddedDocument.prototype.markModified = function(path) {
9658
+ this.$__.activePaths.modify(path);
9642
9659
if (!this.__parentArray) return;
9643
9660
9644
- this.$__.activePaths.modify(path);
9645
9661
if (this.isNew) {
9646
9662
// Mark the WHOLE parent array as modified
9647
9663
// if this is a new document (i.e., we are initializing
0 commit comments