Skip to content

Commit

Permalink
populate; depopulate populated single paths
Browse files Browse the repository at this point in the history
also fixes legacy issue where single populated path
was markedModified causing populated document to
overwrite _id.

relates to #570
  • Loading branch information
aheckmann committed Feb 3, 2013
1 parent 5b79f81 commit 8a60a88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/document.js
Expand Up @@ -1417,6 +1417,11 @@ Document.prototype._doQueue = function () {
*/

Document.prototype.toObject = function (options) {
// check for populated paths that we set to a document
if (options && options.convertToId) {
return clone(this._id, options);
}

// When internally saving this document we always pass options,
// bypassing the custom schema options.
if (!(options && 'Object' == options.constructor.name)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/model.js
Expand Up @@ -353,7 +353,7 @@ Model.prototype._delta = function _delta () {
operand(self, where, delta, data, value);

} else {
value = utils.clone(value);
value = utils.clone(value, { convertToId: 1 });
operand(self, where, delta, data, value);
}
}
Expand Down
1 change: 1 addition & 0 deletions test/model.populate.test.js
Expand Up @@ -2146,6 +2146,7 @@ describe('model: populate:', function(){
assert.equal(doc.fans[5], user7.id);
assert.equal(doc.fans[6], null);
assert.equal(doc.fans[7], String(_id));
assert.equal(String(doc._creator), creator._id);
done();
})
})
Expand Down

0 comments on commit 8a60a88

Please sign in to comment.