From df57805b949a8f2b6c52f5543701bce409f7aad4 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Wed, 11 Apr 2012 19:36:10 +0400 Subject: [PATCH] Turn off caching --- lib/abstract-class.js | 2 ++ test/common_test.js | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/abstract-class.js b/lib/abstract-class.js index a5237812..8934fc26 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -658,6 +658,7 @@ AbstractClass.hasMany = function hasMany(anotherClass, params) { function find(id, cb) { anotherClass.find(id, function (err, inst) { if (err) return cb(err); + if (!inst) return cb(new Error('Not found')); if (inst[fk] == this.id) { cb(null, inst); } else { @@ -863,6 +864,7 @@ function defineReadonlyProp(obj, key, value) { * Add object to cache */ function addToCache(constr, obj) { + return; touchCache(constr, obj.id); constr.cache[obj.id] = obj; } diff --git a/test/common_test.js b/test/common_test.js index 8f826e47..9d022ff8 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -234,13 +234,14 @@ function testOrm(schema) { post.save(function () { test.ok(post.a); post.reload(function (err, psto) { - test.ok(!post.a); + test.ok(!psto.a); test.done(); }); }); }); }); + /* it('should not create new instances for the same object', function (test) { var title = 'Initial title'; Post.create({ title: title }, function (err, post) { @@ -254,6 +255,7 @@ function testOrm(schema) { }); }); }); + */ it('should not re-instantiate object on saving', function (test) { var title = 'Initial title'; @@ -311,7 +313,7 @@ function testOrm(schema) { test.ok(!post.propertyChanged('title')); test.equal(post.content, 'New content', 'dirty state saved'); test.ok(post.propertyChanged('content')); - post.reload(function () { + post.reload(function (err, post) { test.equal(post.title, 'New title'); test.ok(!post.propertyChanged('title')); test.equal(post.content, 'content', 'real value turned back'); @@ -401,7 +403,7 @@ function testOrm(schema) { if (err) return console.log(err); // test.ok(post.author(), u.id); u.posts(function (err, posts) { - test.strictEqual(posts.pop(), post); + test.strictEqual(posts.pop().id, post.id); test.done(); }); });