Skip to content

Commit a472bf8

Browse files
committed
Merge pull request #575 from benkitzelman/expose-dirtyness
Exposing dirtyProperties array on the instance
2 parents 2324d34 + 1d9b860 commit a472bf8

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/Instance.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ function Instance(Model, opts) {
647647
enumerable: false,
648648
writable: true
649649
});
650+
Object.defineProperty(instance, "dirtyProperties", {
651+
get: function () { return opts.changes; },
652+
enumerable: false
653+
});
650654
Object.defineProperty(instance, "isInstance", {
651655
value: true,
652656
enumerable: false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"sqlite",
1313
"mongodb"
1414
],
15-
"version" : "2.1.19",
15+
"version" : "2.1.20",
1616
"license" : "MIT",
1717
"homepage" : "http://dresende.github.io/node-orm2",
1818
"repository" : "http://github.com/dresende/node-orm2.git",

test/integration/instance.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,27 @@ describe("Model instance", function() {
276276
});
277277
});
278278

279+
describe("#dirtyProperties", function () {
280+
var person = null;
281+
282+
beforeEach(function (done) {
283+
Person.create({ name: 'John', age: 44, data: { a: 1 } }, function (err, p) {
284+
if (err) return cb(err);
285+
286+
person = p;
287+
done();
288+
});
289+
});
290+
291+
it("should mark individual properties as dirty", function () {
292+
should.equal(person.saved(), true);
293+
person.markAsDirty('name');
294+
person.markAsDirty('data');
295+
should.equal(person.saved(), false);
296+
should.equal(person.dirtyProperties.join(','), 'name,data');
297+
});
298+
});
299+
279300
describe("#isShell", function () {
280301
it("should return true for shell models", function () {
281302
should.equal(Person(4).isShell(), true);

0 commit comments

Comments
 (0)