diff --git a/lib/mongoose/document.js b/lib/mongoose/document.js index 37481547dab..a11baebdbc0 100644 --- a/lib/mongoose/document.js +++ b/lib/mongoose/document.js @@ -554,13 +554,6 @@ function compile (tree, proto, prefix) { , limb , key; - if (!proto.__roots) { - Object.defineProperty(proto, '__keys', { - enumerable: false - , value: keys - }); - } - while (i--) { key = keys[i]; limb = tree[key]; @@ -572,7 +565,8 @@ function compile (tree, proto, prefix) { ? limb : null) , proto - , prefix); + , prefix + , keys); } }; @@ -580,7 +574,7 @@ function compile (tree, proto, prefix) { * Defines the accessor named prop on the incoming prototype. */ -function define (prop, subprops, prototype, prefix) { +function define (prop, subprops, prototype, prefix, keys) { var prefix = prefix || '' , path = (prefix ? prefix + '.' : '') + prop; @@ -588,18 +582,16 @@ function define (prop, subprops, prototype, prefix) { Object.defineProperty(prototype, prop, { enumerable: true - , get: function ( ) { + , get: function () { if (!this.__getters) this.__getters = {}; if (!this.__getters[path]) { var nested = Object.create(this); - nested.__keys = undefined; // shadow inherited getters from sub-objects so // thing.nested.nested.nested... doesn't occur (gh-366) var i = 0 - , keys = prototype.__keys , len = keys.length; for (; i < len; ++i) {