Skip to content

Commit

Permalink
fixed; compat with non-schema path props using positional notation
Browse files Browse the repository at this point in the history
fixes #1048
  • Loading branch information
aheckmann committed Aug 16, 2012
1 parent 33d6dc9 commit 6dd0503
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/schema.js
Expand Up @@ -358,12 +358,15 @@ function getPositionalPath (self, path) {
return self.paths[subpaths[0]];
}

var val = self.path(subpaths[0])
, last = subpaths.length - 1
, subpath;
var val = self.path(subpaths[0]);
if (!val) return val;

for (var i = 1; i < subpaths.length; ++i) {
var subpath = subpaths[i];
var last = subpaths.length - 1
, subpath
, i = 1;

for (; i < subpaths.length; ++i) {
subpath = subpaths[i];

if (i === last &&
val &&
Expand Down
30 changes: 30 additions & 0 deletions test/model.test.js
Expand Up @@ -3955,6 +3955,36 @@ describe('model', function(){
done();
});
});

it('with positional notation on path not existing in schema (gh-1048)', function(done){
var db = start();

var M = db.model('backwardCompat-gh-1048', Schema({ name: 'string' }));
db.on('open', function () {
var o = {
name: 'gh-1048'
, _id: new mongoose.Types.ObjectId
, databases: {
0: { keys: 100, expires: 0}
, 15: {keys:1,expires:0}
}
};

M.collection.insert(o, { safe: true }, function (err) {
assert.ifError(err);
M.findById(o._id, function (err, doc) {
db.close();
assert.ifError(err);
assert.ok(doc);
assert.ok(doc._doc.databases);
assert.ok(doc._doc.databases['0']);
assert.ok(doc._doc.databases['15']);
assert.equal(undefined, doc.databases);
done();
})
})
});
})
});

describe('create()', function(){
Expand Down

0 comments on commit 6dd0503

Please sign in to comment.