Skip to content

Commit

Permalink
fixes gh-1954
Browse files Browse the repository at this point in the history
  • Loading branch information
archangel-irk committed Mar 11, 2014
1 parent 004a9e7 commit d5dc40f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/document.js
Expand Up @@ -629,6 +629,8 @@ Document.prototype.$__set = function (
} else {
if (obj[parts[i]] && 'Object' === obj[parts[i]].constructor.name) {
obj = obj[parts[i]];
} else if (obj[parts[i]] && 'EmbeddedDocument' === obj[parts[i]].constructor.name) {
obj = obj[parts[i]];
} else if (obj[parts[i]] && Array.isArray(obj[parts[i]])) {
obj = obj[parts[i]];
} else {
Expand Down
17 changes: 17 additions & 0 deletions test/document.test.js
Expand Up @@ -60,6 +60,7 @@ var schema = new Schema({
}
, em: [em]
, date: Date
, schedule: [ new Schema({open: Number, close: Number}) ]
});
TestDocument.prototype.$__setSchema(schema);

Expand Down Expand Up @@ -1069,6 +1070,22 @@ describe('document', function(){
assert.ok(!doc.isModified('nested.age'));
assert.ok(doc.isModified('nested.deep'));
assert.equal('Hank and Marie', doc.nested.deep.x);

var doc = new TestDocument();
doc.init({
schedule: [{
open: 1000,
close: 1900
}]
});

doc.set('schedule.0.open', 1100);
assert.ok(doc.schedule);
assert.equal('MongooseDocumentArray', doc.schedule.constructor.name);
assert.equal('EmbeddedDocument', doc.schedule[0].constructor.name);
assert.equal(1100, doc.schedule[0].open);
assert.equal(1900, doc.schedule[0].close);

done();
})
})
Expand Down

0 comments on commit d5dc40f

Please sign in to comment.