MCPcopy Create free account
hub / github.com/Automattic/mongoose / DocumentArray

Function DocumentArray

bin/mongoose.js:6700–6738  ·  view source on GitHub ↗

* SubdocsArray SchemaType constructor * * @param {String} key * @param {Schema} schema * @param {Object} options * @inherits SchemaArray * @api public

(key, schema, options)

Source from the content-addressed store, hash-verified

6698 */
6699
6700function DocumentArray(key, schema, options) {
6701 // compile an embedded document for this schema
6702 function EmbeddedDocument() {
6703 Subdocument.apply(this, arguments);
6704 }
6705
6706 EmbeddedDocument.prototype = Object.create(Subdocument.prototype);
6707 EmbeddedDocument.prototype.$__setSchema(schema);
6708 EmbeddedDocument.schema = schema;
6709
6710 // apply methods
6711 for (var i in schema.methods) {
6712 EmbeddedDocument.prototype[i] = schema.methods[i];
6713 }
6714
6715 // apply statics
6716 for (i in schema.statics) {
6717 EmbeddedDocument[i] = schema.statics[i];
6718 }
6719
6720 EmbeddedDocument.options = options;
6721
6722 ArrayType.call(this, key, EmbeddedDocument, options);
6723
6724 this.schema = schema;
6725 this.$isMongooseDocumentArray = true;
6726 var fn = this.defaultValue;
6727
6728 if (!('defaultValue' in this) || fn !== void 0) {
6729 this.default(function() {
6730 var arr = fn.call(this);
6731 if (!Array.isArray(arr)) {
6732 arr = [arr];
6733 }
6734 // Leave it up to `cast()` to convert this to a documentarray
6735 return arr;
6736 });
6737 }
6738}
6739
6740/**
6741 * This schema type's name, to defend against minifiers that mangle

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected