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
This commit is contained in:
kirrg001 2019-02-06 19:57:09 +01:00 committed by Katharina Irrgang
parent 2fd4cbb93b
commit 68bdcfc753

View File

@ -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));
},
/**