(schema, options, baseClass)
| 120 | */ |
| 121 | |
| 122 | function _createConstructor(schema, options, baseClass) { |
| 123 | Subdocument || (Subdocument = require('../types/ArraySubdocument')); |
| 124 | |
| 125 | // compile an embedded document for this schema |
| 126 | function EmbeddedDocument() { |
| 127 | Subdocument.apply(this, arguments); |
| 128 | if (this.__parentArray == null || this.__parentArray.getArrayParent() == null) { |
| 129 | return; |
| 130 | } |
| 131 | this.$session(this.__parentArray.getArrayParent().$session()); |
| 132 | } |
| 133 | |
| 134 | schema._preCompile(); |
| 135 | |
| 136 | const proto = baseClass != null ? baseClass.prototype : Subdocument.prototype; |
| 137 | EmbeddedDocument.prototype = Object.create(proto); |
| 138 | EmbeddedDocument.prototype.$__setSchema(schema); |
| 139 | EmbeddedDocument.schema = schema; |
| 140 | EmbeddedDocument.prototype.constructor = EmbeddedDocument; |
| 141 | EmbeddedDocument.$isArraySubdocument = true; |
| 142 | EmbeddedDocument.events = new EventEmitter(); |
| 143 | EmbeddedDocument.base = schema.base; |
| 144 | |
| 145 | // apply methods |
| 146 | for (const i in schema.methods) { |
| 147 | EmbeddedDocument.prototype[i] = schema.methods[i]; |
| 148 | } |
| 149 | |
| 150 | // apply statics |
| 151 | for (const i in schema.statics) { |
| 152 | EmbeddedDocument[i] = schema.statics[i]; |
| 153 | } |
| 154 | |
| 155 | for (const i in EventEmitter.prototype) { |
| 156 | EmbeddedDocument[i] = EventEmitter.prototype[i]; |
| 157 | } |
| 158 | |
| 159 | EmbeddedDocument.options = options; |
| 160 | |
| 161 | return EmbeddedDocument; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Adds a discriminator to this document array. |
no test coverage detected