Skip to content

Commit

Permalink
fix(document): support skipping timestamps on save() with `save({ tim…
Browse files Browse the repository at this point in the history
…estamps: false })`

Fix #7357
  • Loading branch information
vkarpov15 committed Jan 12, 2019
1 parent 3d48a22 commit 17819f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/model.js
Expand Up @@ -465,8 +465,11 @@ Model.prototype.save = function(options, fn) {
return cb(parallelSave);
}

this.$__.saveOptions = options;

this.$__save(options, error => {
this.$__.saving = undefined;
delete this.$__.saveOptions;

if (error) {
this.$__handleReject(error);
Expand Down
4 changes: 4 additions & 0 deletions lib/schema.js
Expand Up @@ -918,6 +918,10 @@ Schema.prototype.setupTimestamp = function(timestamps) {
this.add(schemaAdditions);

this.pre('save', function(next) {
if (get(this, '$__.saveOptions.timestamps') === false) {
return next();
}

const defaultTimestamp = (this.ownerDocument ? this.ownerDocument() : this).
constructor.base.now();
const auto_id = this._id && this._id.auto;
Expand Down

0 comments on commit 17819f1

Please sign in to comment.