Permalink
Browse files

fixed; 'path' is now a valid pathname

closes #356
  • Loading branch information...
aheckmann committed May 20, 2011
1 parent a05e794 commit 73fda8d7da3dd8537288ac4767381fa828fd8d57
Showing with 13 additions and 11 deletions.
  1. +9 −7 lib/mongoose/document.js
  2. +1 −1 lib/mongoose/model.js
  3. +3 −3 test/schema.onthefly.test.js
View
@@ -194,6 +194,7 @@ Document.prototype.set = function (path, val, type) {
adhocs = this._adhocPaths || (this._adhocPaths = {});
adhocs[path] = Schema.interpretAsType(path, type);
}
+
if ('string' !== typeof path) {
if (null === path || undefined === path)
@@ -213,7 +214,7 @@ Document.prototype.set = function (path, val, type) {
while (i--) {
key = keys[i];
- if (!(this.path(prefix + key) instanceof MixedSchema)
+ if (!(this._path(prefix + key) instanceof MixedSchema)
&& undefined !== path[key]
&& null !== path[key]
&& Object == path[key].constructor) {
@@ -226,7 +227,7 @@ Document.prototype.set = function (path, val, type) {
return this;
}
- var schema = this.path(path)
+ var schema = this._path(path)
, parts = path.split('.')
, obj = this.doc
, self = this;
@@ -365,7 +366,7 @@ Document.prototype.get = function (path, type) {
adhocs[path] = Schema.interpretAsType(path, type);
}
var obj
- , schema = this.path(path) || this.schema.virtualpath(path)
+ , schema = this._path(path) || this.schema.virtualpath(path)
, adhocs
, pieces = path.split('.');
@@ -386,8 +387,10 @@ Document.prototype.get = function (path, type) {
* in the schema's list of type schemas
* @param {String} path
* @param {Object} obj
+ * @api private
*/
-Document.prototype.path = function (path, obj) {
+
+Document.prototype._path = function (path, obj) {
var adhocs = this._adhocPaths
, adhocType = adhocs && adhocs[path];
if (adhocType) {
@@ -397,7 +400,6 @@ Document.prototype.path = function (path, obj) {
}
};
-
/**
* Commits a path, marking as modified if needed. Useful for mixed keys
*
@@ -473,8 +475,8 @@ Document.prototype.isModified = function (path) {
* that we want to send to MongoDB on a Document save.
*
* @param {String} path
- *
*/
+
Document.prototype.isDirectModified = function (path) {
return (path in this.activePaths.states.modify);
};
@@ -704,13 +706,13 @@ Document.prototype.inspect = function () {
return inspect(this.doc);
};
-
/**
* Returns true if the Document stores the same data as doc.
* @param {Document} doc to compare to
* @return {Boolean}
* @api public
*/
+
Document.prototype.equals = function (doc) {
return this.get('_id') === doc.get('_id');
};
View
@@ -81,7 +81,7 @@ Model.prototype.save = function (fn) {
var dirty = this.activePaths.map('modify', function (path) {
return { path: path
, value: self.getValue(path)
- , schema: self.path(path) };
+ , schema: self._path(path) };
});
if (this.isNew) {
@@ -34,11 +34,11 @@ module.exports = {
var postOne = new Decorated();
postOne.set('adhoc', '9', Number);
- postOne.path('adhoc').should.not.equal(undefined);
+ postOne._path('adhoc').should.not.equal(undefined);
var postTwo = new Decorated();
- postTwo.path('title').should.not.equal(undefined);
- should.strictEqual(undefined, postTwo.path('adhoc'));
+ postTwo._path('title').should.not.equal(undefined);
+ should.strictEqual(undefined, postTwo._path('adhoc'));
db.close();
},

0 comments on commit 73fda8d

Please sign in to comment.