diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 1c89d36d..08050e93 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -326,14 +326,17 @@ AbstractClass.all = function all(params, cb) { } var constr = this; this.schema.adapter.all(this.modelName, params, function (err, data) { - var collection = null; + var collection = null, cache = {}; if (data && data.map) { collection = new Array(); data.forEach(function (d, i) { collection.__defineGetter__(i, function () { + if (cache[i]) { + return cache[i]; + } var obj = new constr; obj._initProperties(d, false); - collection[i] = obj; + cache[i] = obj; return obj; }); }); @@ -535,7 +538,7 @@ AbstractClass.prototype.toObject = function (onlySchema) { }; AbstractClass.prototype.hasOwnProperty = function (prop) { - return this.__data.hasOwnProperty(prop) || + return this.__data && this.__data.hasOwnProperty(prop) || Object.getOwnPropertyNames(this).indexOf(prop) !== -1; }; diff --git a/package.json b/package.json index cf652e3c..268edb6d 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "main": "index.js", "scripts": { - "test": "EXCEPT=cradle nodeunit test/*_test*" + "test": "EXCEPT=cradle,neo4j nodeunit test/*_test*" }, "engines": [ "node >= 0.4.12"