From 68bdcfc753f615907a19d2eee0fd6966f34c74f6 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Wed, 6 Feb 2019 19:57:09 +0100 Subject: [PATCH] Fixed model._changed for creating resources no issue - discovered while testing - the events are still triggered though for posts because .authors are added on creation --- core/server/models/base/index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/server/models/base/index.js b/core/server/models/base/index.js index 50d393c7b1..cdfd40b8b1 100644 --- a/core/server/models/base/index.js +++ b/core/server/models/base/index.js @@ -283,7 +283,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ * * Exceptions: internal context or importing */ - onCreating: function onCreating(newObj, attr, options) { + onCreating: function onCreating(model, attr, options) { if (schema.tables[this.tableName].hasOwnProperty('created_by')) { if (!options.importing || (options.importing && !this.get('created_by'))) { this.set('created_by', this.contextUser(options)); @@ -297,18 +297,20 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ } if (schema.tables[this.tableName].hasOwnProperty('created_at')) { - if (!newObj.get('created_at')) { - newObj.set('created_at', new Date()); + if (!model.get('created_at')) { + model.set('created_at', new Date()); } } if (schema.tables[this.tableName].hasOwnProperty('updated_at')) { - if (!newObj.get('updated_at')) { - newObj.set('updated_at', new Date()); + if (!model.get('updated_at')) { + model.set('updated_at', new Date()); } } - return Promise.resolve(this.onValidate(newObj, attr, options)); + model._changed = _.cloneDeep(model.changed); + + return Promise.resolve(this.onValidate(model, attr, options)); }, /**