From e72db08ad0df196ecc3f01f5ebd74156eb52db9a Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Mon, 28 Nov 2011 23:31:01 +0700 Subject: [PATCH] Reset changes method --- lib/abstract-class.js | 15 ++++++++++----- test/{perf_test.coffee => performance.coffee} | 0 2 files changed, 10 insertions(+), 5 deletions(-) rename test/{perf_test.coffee => performance.coffee} (100%) diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 2fa12c7b..e231482a 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -394,15 +394,20 @@ AbstractClass.prototype.propertyChanged = function (attr) { AbstractClass.prototype.reload = function (cb) { var obj = this.constructor.cache[this.id]; if (obj) { - Object.keys(obj).forEach(function (k) { - if (obj.propertyChanged(k)) { - obj[k] = obj[k + '_was']; - } - }); + obj.reset(); } this.constructor.find(this.id, cb); }; +AbstractClass.prototype.reset = function () { + var obj = this; + Object.keys(obj).forEach(function (k) { + if (obj.propertyChanged(k)) { + obj[k] = obj[k + '_was']; + } + }); +}; + // relations AbstractClass.hasMany = function (anotherClass, params) { var methodName = params.as; // or pluralize(anotherClass.modelName) diff --git a/test/perf_test.coffee b/test/performance.coffee similarity index 100% rename from test/perf_test.coffee rename to test/performance.coffee