Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow specifying collection name in schema

Thanks @ixti

Pull request 470
  • Loading branch information...
commit 80897da5c4bf0646416b1c35c1e1eb43f14fa0e6 1 parent afe7370
@aheckmann aheckmann authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/index.js
View
10 lib/index.js
@@ -158,8 +158,6 @@ Mongoose.prototype.model = function (name, schema, collection, skipInit) {
collection = null;
}
- collection || (collection = utils.toCollectionName(name));
-
// look up models for the collection
if (!this.modelSchemas[name]) {
if (name in SchemaDefaults) {
@@ -177,6 +175,14 @@ Mongoose.prototype.model = function (name, schema, collection, skipInit) {
}
}
+ if (!schema) {
+ schema = this.modelSchemas[name];
+ }
+
+ if (!collection) {
+ collection = schema.set('collection') || utils.toCollectionName(name);
+ }
+
if (!this.models[name]) {
var model = Model.compile(name
, this.modelSchemas[name]
Please sign in to comment.
Something went wrong with that request. Please try again.