Created
October 18, 2011 17:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** | |
* 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