Permalink
Browse files

fixed; nested objects now convert to JSON properly

  • Loading branch information...
1 parent 2bd64a0 commit f6e547e7f2378670e743f05f95a09a7ceb9317ab @aheckmann aheckmann committed Mar 26, 2011
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/mongoose/document.js
@@ -437,22 +437,24 @@ function define (prop, subprops, prototype, prefix) {
if (!this.__getters)
this.__getters = {};
- if (!this.__getters[path]){
+ if (!this.__getters[path]) {
var nested = function(){};
nested.prototype.__proto__ = this;
+ nested.prototype.toObject = function () {
+ return this.get(path);
+ };
compile(subprops, nested.prototype, path);
this.__getters[path] = new nested();
}
return this.__getters[path];
});
} else {
- prototype.__defineGetter__(prop, function () {
- return this.get(path);
- });
- prototype.__defineSetter__(prop, function (v) {
- return this.set(path, v);
+ Object.defineProperty(prototype, prop, {
+ get: function ( ) { return this.get(path); }
+ , set: function (v) { return this.set(path, v); }
+ , enumerable: true
});
}
};

0 comments on commit f6e547e

Please sign in to comment.