Permalink
Browse files

name yaken from connection

  • Loading branch information...
1 parent b49ce6d commit 42d1146664a2795dfeafe8143d3b453982606747 @goulash1971 goulash1971 committed Jul 5, 2011
Showing with 13 additions and 5 deletions.
  1. +13 −5 lib/plugins/resolveDBRefs.js
View
18 lib/plugins/resolveDBRefs.js
@@ -77,9 +77,12 @@ exports.resolveDBRefs = resolveDBRefs = function resolveDBRefs (schema, options)
if (!force) {
callback(null, this[cache]);
} else {
+ var con = this.db.db;
+ if ((typeof con === 'undefined') || (con === null))
+ throw new Error('mongoose connection not open');
var self = this;
- this.db.db.dereference(val, function(err, doc) {
- self[cache] = doc; callback(err, doc) });
+ con.dereference(val, function(err, doc) {
+ self[cache] = doc; callback(err, doc) });
}
}
});
@@ -88,21 +91,26 @@ exports.resolveDBRefs = resolveDBRefs = function resolveDBRefs (schema, options)
if (value !== null)
this[path] = dbref.prototype.cast(
{"$ref": value.collection.name,
- "$id": value._id, "$db": value.db.db.databaseName});
+ "$id": value._id, "$db": value.db.name});
else this[path] = null;
});
} else {
schema.method(names['getter'], function(callback) {
var val = this[path];
if ((typeof val === 'undefined') || (val === null))
callback(null, null);
- else this.db.db.dereference(val, callback);
+ else {
+ var con = this.db.db;
+ if ((typeof con === 'undefined') || (con === null))
+ throw new Error('mongoose connection not open');
+ con.dereference(val, callback);
+ }
});
schema.method(names['setter'], function(value) {
if (value !== null)
this[path] = dbref.prototype.cast(
{"$ref": value.collection.name,
- "$id": value._id, "$db": value.db.db.databaseName});
+ "$id": value._id, "$db": value.db.name});
else this[path] = null;
});
}

0 comments on commit 42d1146

Please sign in to comment.