* A constructor. * * @param {object} obj js object returned from the db * @param {MongooseDocumentArray} parentArr the parent array of this document * @param {boolean} skipId * @param {object} fields * @param {number} index * @inherits Document * @api private
(obj, parentArr, skipId, fields, index)
| 24 | */ |
| 25 | |
| 26 | function ArraySubdocument(obj, parentArr, skipId, fields, index) { |
| 27 | let parent; |
| 28 | if (utils.isMongooseDocumentArray(parentArr)) { |
| 29 | this.__parentArray = parentArr; |
| 30 | parent = parentArr[arrayParentSymbol]; |
| 31 | } else { |
| 32 | this.__parentArray = undefined; |
| 33 | } |
| 34 | this[documentArrayParent] = parent; |
| 35 | this.$setIndex(index); |
| 36 | this.$__parent = parent; |
| 37 | |
| 38 | const options = { isNew: true }; |
| 39 | if (parent != null && 'defaults' in parent.$__) { |
| 40 | options.defaults = parent.$__.defaults; |
| 41 | } |
| 42 | if (typeof skipId === 'object' && skipId != null) { |
| 43 | Object.assign(options, skipId); |
| 44 | } |
| 45 | |
| 46 | Subdocument.call(this, obj, fields, null, options); |
| 47 | } |
| 48 | |
| 49 | /*! |
| 50 | * Inherit from Subdocument |
nothing calls this directly
no outgoing calls
no test coverage detected