Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v7.1.0
- Add `isDirty` function to instances ([859](../../pull/859))

### v7.0.0
- Update `async` package from v2 to v3 to resolve security vulnerabilities ([858](../../pull/858))
- Drop support for node < 6 (due to `async` package update)
Expand Down
6 changes: 6 additions & 0 deletions lib/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ function Instance(Model, opts) {
get: function () { return opts.changes; },
enumerable: false
});
Object.defineProperty(instance, "isDirty", {
value: function () {
return opts.changes.length > 0;
},
enumerable: false
});
Object.defineProperty(instance, "isInstance", {
value: true,
enumerable: false
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"sqlite",
"mongodb"
],
"version": "7.0.0",
"version": "7.1.0",
"license": "MIT",
"homepage": "http://dresende.github.io/node-orm2",
"repository": "http://github.com/dresende/node-orm2.git",
Expand Down
29 changes: 29 additions & 0 deletions test/integration/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,35 @@ describe("Model instance", function() {
});
});

describe("#isDirty", 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 return false by default", function () {
should.equal(person.isDirty(), false);
});

it("should return false when property is set to same value", function () {
should.equal(person.isDirty(), false);
person.name = 'John';
should.equal(person.isDirty(), false);
});

it("should return true when property is changed", function () {
should.equal(person.isDirty(), false);
person.name = 'Bob';
should.equal(person.isDirty(), true);
});
});

describe("#isShell", function () {
it("should return true for shell models", function () {
should.equal(Person(4).isShell(), true);
Expand Down