@@ -8,13 +8,14 @@ var ArrayType = require('./array');
88var CastError = require ( '../error/cast' ) ;
99var Document = require ( '../document' ) ;
1010var EventEmitter = require ( 'events' ) . EventEmitter ;
11- var MongooseDocumentArray = require ( '../types/documentarray' ) ;
1211var SchemaType = require ( '../schematype' ) ;
13- var Subdocument = require ( '../types/embedded' ) ;
1412var discriminator = require ( '../services/model/discriminator' ) ;
1513var util = require ( 'util' ) ;
1614var utils = require ( '../utils' ) ;
1715
16+ var MongooseDocumentArray ;
17+ var Subdocument ;
18+
1819/**
1920 * SubdocsArray SchemaType constructor
2021 *
@@ -66,6 +67,8 @@ DocumentArray.prototype.constructor = DocumentArray;
6667 */
6768
6869function _createConstructor ( schema , options ) {
70+ Subdocument || ( Subdocument = require ( '../types/embedded' ) ) ;
71+
6972 // compile an embedded document for this schema
7073 function EmbeddedDocument ( ) {
7174 Subdocument . apply ( this , arguments ) ;
@@ -130,6 +133,9 @@ DocumentArray.prototype.discriminator = function(name, schema) {
130133 */
131134
132135DocumentArray . prototype . doValidate = function ( array , fn , scope , options ) {
136+ // lazy load
137+ MongooseDocumentArray || ( MongooseDocumentArray = require ( '../types/documentarray' ) ) ;
138+
133139 var _this = this ;
134140 SchemaType . prototype . doValidate . call ( this , array , function ( err ) {
135141 if ( err ) {
@@ -251,6 +257,9 @@ DocumentArray.prototype.doValidateSync = function(array, scope) {
251257 */
252258
253259DocumentArray . prototype . cast = function ( value , doc , init , prev , options ) {
260+ // lazy load
261+ MongooseDocumentArray || ( MongooseDocumentArray = require ( '../types/documentarray' ) ) ;
262+
254263 var selected ;
255264 var subdoc ;
256265 var i ;
0 commit comments