Skip to content

Commit

Permalink
fixed; connection assignment in Model#model
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Apr 23, 2012
1 parent 408f1f2 commit ce45df8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/connection.js
Expand Up @@ -398,7 +398,7 @@ Connection.prototype.model = function (name, schema, collection) {
var model = this.base.model(name, schema, collection, true)
, Model

if (this != model.prototype.connection) {
if (this != model.prototype.db) {
// subclass model using this connection and collection name
Model = function Model () {
model.apply(this, arguments);
Expand Down
7 changes: 7 additions & 0 deletions test/connection.test.js
Expand Up @@ -295,6 +295,13 @@ module.exports = {
db.close();
},

'connection.model should properly assign the db': function () {
var A = mongoose.model('testing853a', new Schema({x:String}), 'testing853-1');
var B = mongoose.model('testing853b', new Schema({x:String}), 'testing853-2');
var C = B.model('testing853a');
should.eql(C, A)
},

'connection error event fires with one listener': function (exit) {
var db= start({ uri: 'mongodb://localasdfads/fakeeee'})
, called = false;
Expand Down

0 comments on commit ce45df8

Please sign in to comment.