Skip to content

Commit

Permalink
cleaner fix for #366
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Jul 26, 2011
1 parent 90772d1 commit bf32ee5
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/mongoose/document.js
Expand Up @@ -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];
Expand All @@ -572,34 +565,33 @@ function compile (tree, proto, prefix) {
? limb
: null)
, proto
, prefix);
, prefix
, keys);
}
};

/**
* 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;

if (subprops) {

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) {
Expand Down

0 comments on commit bf32ee5

Please sign in to comment.