From 9d57ab0f1eec709225d1a0f8765908228dea4777 Mon Sep 17 00:00:00 2001 From: Ben Kitzelman Date: Tue, 18 Nov 2014 16:45:19 +1100 Subject: [PATCH 1/3] Exposing dirtyProperties array on the instance --- lib/Instance.js | 4 ++++ test/integration/instance.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/Instance.js b/lib/Instance.js index beefce89..d733f619 100755 --- a/lib/Instance.js +++ b/lib/Instance.js @@ -647,6 +647,10 @@ function Instance(Model, opts) { enumerable: false, writable: true }); + Object.defineProperty(instance, "dirtyProperties", { + get: function () { return opts.changes; }, + enumerable: true + }); Object.defineProperty(instance, "isInstance", { value: true, enumerable: false diff --git a/test/integration/instance.js b/test/integration/instance.js index 7526340e..72fe54ec 100644 --- a/test/integration/instance.js +++ b/test/integration/instance.js @@ -276,6 +276,27 @@ describe("Model instance", function() { }); }); + describe("#dirtyProperties", function () { + var person = null; + + beforeEach(function (done) { + Person.create({ name: 'John', age: 44, data: { a: 1 } }, function (err, p) { + if (err) return cb(err); + + person = p; + done(); + }); + }); + + it("should mark individual properties as dirty", function () { + should.equal(person.saved(), true); + person.markAsDirty('name'); + person.markAsDirty('data'); + should.equal(person.saved(), false); + should.equal(person.dirtyProperties.join(','), 'name,data'); + }); + }); + describe("#isShell", function () { it("should return true for shell models", function () { should.equal(Person(4).isShell(), true); From c200656e8a6e13db4a8a2d42faae49bc3752755e Mon Sep 17 00:00:00 2001 From: Ben Kitzelman Date: Tue, 18 Nov 2014 16:48:55 +1100 Subject: [PATCH 2/3] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 883887e5..192988b9 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "sqlite", "mongodb" ], - "version" : "2.1.19", + "version" : "2.1.20", "license" : "MIT", "homepage" : "http://dresende.github.io/node-orm2", "repository" : "http://github.com/dresende/node-orm2.git", From 1d9b8602821d6c0769f3846cc6e688bdb9adbab0 Mon Sep 17 00:00:00 2001 From: Ben Kitzelman Date: Wed, 19 Nov 2014 10:06:44 +1100 Subject: [PATCH 3/3] dirty props should not be enumerable off the instance --- lib/Instance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Instance.js b/lib/Instance.js index d733f619..9670ddc4 100755 --- a/lib/Instance.js +++ b/lib/Instance.js @@ -649,7 +649,7 @@ function Instance(Model, opts) { }); Object.defineProperty(instance, "dirtyProperties", { get: function () { return opts.changes; }, - enumerable: true + enumerable: false }); Object.defineProperty(instance, "isInstance", { value: true,