Skip to content

Commit

Permalink
Avoid mongoose issues with toObject
Browse files Browse the repository at this point in the history
  • Loading branch information
ivank committed Jul 7, 2017
1 parent 4ff2707 commit 3daac07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongoose-originals",
"version": "1.3.0",
"version": "1.3.1",
"description": "Get original value of mongoose fields",
"main": "src/index.js",
"repository": "git@github.com:enhancv/mongoose-originals.git",
Expand Down
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ function mongooseOriginals(schema, userOptions) {
}

function isChanged() {
return !this.original || !isEqual(this.original, pick(options.fields, this.toObject()));
return (
!this.original ||
!isEqual(
this.original,
pick(options.fields, this.toObject({ getters: false, transform: false }))
)
);
}

function setSnapshotOriginal() {
Expand All @@ -40,7 +46,7 @@ function mongooseOriginals(schema, userOptions) {

function saveOriginalNamed() {
this.original = {};
const newValues = this.toObject();
const newValues = this.toObject({ getters: false, transform: false });

options.fields.forEach(name => {
this.original[name] = newValues[name];
Expand Down
2 changes: 1 addition & 1 deletion test/indexTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe(
}, /No fields specified for mongoose originals on schema/);
});

it.only("Should test nested setSnapshotOriginal and clearSnapshotOriginal", function() {
it("Should test nested setSnapshotOriginal and clearSnapshotOriginal", function() {
const nested = new Nested({
name: "11",
embedded: { name: "22", children: [{ title: "33" }, { title: "44" }] },
Expand Down

0 comments on commit 3daac07

Please sign in to comment.