This commit is contained in:
Jonasz Bigda
2023-03-25 21:51:42 +01:00
parent 0db1d5117e
commit b332e9ceb0
1044 changed files with 37502 additions and 63938 deletions

View File

@@ -62,7 +62,7 @@ function _createConstructor(schema, baseClass) {
const _embedded = function SingleNested(value, path, parent) {
const _this = this;
this.$parent = parent;
this.$__parent = parent;
Subdocument.apply(this, arguments);
this.$session(this.ownerDocument().$session());
@@ -147,7 +147,7 @@ SingleNestedPath.prototype.$conditionalHandlers.$exists = $exists;
* @api private
*/
SingleNestedPath.prototype.cast = function(val, doc, init, priorVal) {
SingleNestedPath.prototype.cast = function(val, doc, init, priorVal, options) {
if (val && val.$isSingleNested && val.parent === doc) {
return val;
}
@@ -169,16 +169,16 @@ SingleNestedPath.prototype.cast = function(val, doc, init, priorVal) {
}
return obj;
}, {});
options = Object.assign({}, options, { priorDoc: priorVal });
if (init) {
subdoc = new Constructor(void 0, selected, doc);
subdoc.init(val);
} else {
if (Object.keys(val).length === 0) {
return new Constructor({}, selected, doc);
return new Constructor({}, selected, doc, undefined, options);
}
return new Constructor(val, selected, doc, undefined, { priorDoc: priorVal });
return new Constructor(val, selected, doc, undefined, options);
}
return subdoc;
@@ -300,6 +300,26 @@ SingleNestedPath.prototype.discriminator = function(name, schema, value) {
return this.caster.discriminators[name];
};
/**
* Sets a default option for all SingleNestedPath instances.
*
* ####Example:
*
* // Make all numbers have option `min` equal to 0.
* mongoose.Schema.Embedded.set('required', true);
*
* @param {String} option - The option you'd like to set the value for
* @param {*} value - value for option
* @return {undefined}
* @function set
* @static
* @api public
*/
SingleNestedPath.defaultOptions = {};
SingleNestedPath.set = SchemaType.set;
/*!
* ignore
*/