* SubdocsArray SchemaType constructor * * @param {String} key * @param {Schema} schema * @param {Object} options * @inherits SchemaArray * @api private
(key, schema, options)
| 5036 | */ |
| 5037 | |
| 5038 | function DocumentArray (key, schema, options) { |
| 5039 | |
| 5040 | // compile an embedded document for this schema |
| 5041 | function EmbeddedDocument () { |
| 5042 | this.$__setSchema(schema); |
| 5043 | // apply methods |
| 5044 | for (var i in schema.methods) { |
| 5045 | this[i] = schema.methods[i]; |
| 5046 | } |
| 5047 | Subdocument.apply(this, arguments); |
| 5048 | } |
| 5049 | |
| 5050 | EmbeddedDocument.prototype = Subdocument.prototype; |
| 5051 | EmbeddedDocument.schema = schema; |
| 5052 | |
| 5053 | // apply statics |
| 5054 | for (var i in schema.statics) |
| 5055 | EmbeddedDocument[i] = schema.statics[i]; |
| 5056 | |
| 5057 | EmbeddedDocument.options = options; |
| 5058 | this.schema = schema; |
| 5059 | |
| 5060 | ArrayType.call(this, key, EmbeddedDocument, options); |
| 5061 | |
| 5062 | this.schema = schema; |
| 5063 | var path = this.path; |
| 5064 | var fn = this.defaultValue; |
| 5065 | |
| 5066 | this.default(function(){ |
| 5067 | var arr = fn.call(this); |
| 5068 | if (!Array.isArray(arr)) arr = [arr]; |
| 5069 | return new MongooseDocumentArray(arr, path, this); |
| 5070 | }); |
| 5071 | } |
| 5072 | |
| 5073 | /** |
| 5074 | * This schema type's name, to defend against minifiers that mangle |
nothing calls this directly
no outgoing calls
no test coverage detected