diff --git a/lib/index.js b/lib/index.js index 604dde42d49..a2600b66bd9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -447,12 +447,11 @@ Mongoose.prototype.pluralize = function(fn) { * @param {String|Function} name model name or class extending Model * @param {Schema} [schema] the schema to use. * @param {String} [collection] name (optional, inferred from model name) - * @param {Boolean} [skipInit] whether to skip initialization (defaults to false) * @return {Model} The model associated with `name`. Mongoose will create the model if it doesn't already exist. * @api public */ -Mongoose.prototype.model = function(name, schema, collection, skipInit) { +Mongoose.prototype.model = function(name, schema, collection, options) { const _mongoose = this instanceof Mongoose ? this : mongoose; if (typeof schema === 'string') { @@ -468,19 +467,8 @@ Mongoose.prototype.model = function(name, schema, collection, skipInit) { 'schema or a POJO'); } - if (typeof collection === 'boolean') { - skipInit = collection; - collection = null; - } - // handle internal options from connection.model() - let options; - if (skipInit && utils.isObject(skipInit)) { - options = skipInit; - skipInit = true; - } else { - options = {}; - } + options = options || {}; if (_mongoose.models.hasOwnProperty(name)) { if (schema != null && @@ -502,7 +490,7 @@ Mongoose.prototype.model = function(name, schema, collection, skipInit) { throw new _mongoose.Error.MissingSchemaError(name); } - const model = _mongoose._model(name, schema, collection, options, skipInit); + const model = _mongoose._model(name, schema, collection, options); _mongoose.connection.models[name] = model; _mongoose.models[name] = model; @@ -514,7 +502,7 @@ Mongoose.prototype.model = function(name, schema, collection, skipInit) { * ignore */ -Mongoose.prototype._model = function(name, schema, collection, options, skipInit) { +Mongoose.prototype._model = function(name, schema, collection, options) { const _mongoose = this instanceof Mongoose ? this : mongoose; let model; @@ -546,10 +534,8 @@ Mongoose.prototype._model = function(name, schema, collection, options, skipInit const connection = options.connection || _mongoose.connection; model = _mongoose.Model.compile(model || name, schema, collection, connection, _mongoose); - if (!skipInit) { - // Errors handled internally, so safe to ignore error - model.init(function $modelInitNoop() {}); - } + // Errors handled internally, so safe to ignore error + model.init(function $modelInitNoop() {}); return model; }; diff --git a/test/types.documentarray.test.js b/test/types.documentarray.test.js index 2ecc4cdb495..651b910a481 100644 --- a/test/types.documentarray.test.js +++ b/test/types.documentarray.test.js @@ -321,7 +321,7 @@ describe('types.documentarray', function() { next(); }); const schema = new Schema({ children: [child] }); - const M = db.model('Test', schema, 'edarecast-' + random()); + const M = db.model('Test', schema); const m = new M; m.save(function(err) { assert.ifError(err);