diff --git a/lib/Instance.js b/lib/Instance.js index beefce89..9670ddc4 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: false + }); Object.defineProperty(instance, "isInstance", { value: true, enumerable: false 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", 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);