Skip to content

Instantly share code, notes, and snippets.

@jessesanford
Created October 18, 2011 17:40
Show Gist options
  • Save jessesanford/1296078 to your computer and use it in GitHub Desktop.
Save jessesanford/1296078 to your computer and use it in GitHub Desktop.
mongoose/lib/types/embedded.js modification to cast Document's to embedded documents
**
* EmbeddedDocument constructor.
*
* @param {Object} object from db
* @param {MongooseDocumentArray} parent array
* @api private
*/
function EmbeddedDocument (obj, parentArr) {
//TODO We might save some time if instead we
//use the original document rather than
//recasting it from a plain Object
if('Document' === typeof obj){
obj = obj.toObject();
}
this.parentArray = parentArr;
this.parent = parentArr._parent;
Document.call(this, obj);
var self = this;
this.on('isNew', function (val) {
self.isNew = val;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment