diff --git a/lib/mongodb.js b/lib/mongodb.js index 685fb6e..1aed537 100644 --- a/lib/mongodb.js +++ b/lib/mongodb.js @@ -108,10 +108,8 @@ MongoDB.prototype.defineForeignKey = function (model, key, cb) { cb(null, MongoObjectID); }; -MongoDB.prototype.collection = function (name) { - if ("undefined" !== typeof (this._models[name].settings.table)) { - name = this._models[name].settings.table; - } +MongoDB.prototype.collection = function (model) { + var name = this.table(model); if (!this.collections[name]) { this.collections[name] = new mongodb.Collection(this.client, name); } @@ -294,3 +292,6 @@ MongoDB.prototype.disconnect = function () { this.client.close(); }; +MongoDB.prototype.table = function(model) { + return this._models[model].model.tableName; +};