From c0baf5fdeed2389dab0eb8fd46cf17c2a42ebb3d Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 17 Jun 2021 16:46:27 +0100 Subject: [PATCH] Moved `formatOnWrite` function to Bookshelf `override` plugin no issue - `formatOnWrite` doesn't override anything in Bookshelf but we use it within the `override` plugin and sub-models may override it, so it's easier to keep these things together --- core/server/models/base/index.js | 5 ----- core/server/models/base/plugins/overrides.js | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/server/models/base/index.js b/core/server/models/base/index.js index 193ac321f2..69aafcf5e4 100644 --- a/core/server/models/base/index.js +++ b/core/server/models/base/index.js @@ -47,11 +47,6 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({ proto.initialize.call(this); }, - // overridable function for models to format attrs only when saving to db - formatOnWrite: function formatOnWrite(attrs) { - return attrs; - }, - hasDateChanged: function (attr) { return moment(this.get(attr)).diff(moment(this.previous(attr))) !== 0; }, diff --git a/core/server/models/base/plugins/overrides.js b/core/server/models/base/plugins/overrides.js index 5cb11dcf0f..4b2f735092 100644 --- a/core/server/models/base/plugins/overrides.js +++ b/core/server/models/base/plugins/overrides.js @@ -33,6 +33,13 @@ module.exports = function (Bookshelf) { return parentSync; }, + // overridable function for models to format attrs only when saving to db + // this function doesn't override anything in Bookshelf but we use this in + // this plugin and sub-models may override it, so it's easier to keep it in here + formatOnWrite: function formatOnWrite(attrs) { + return attrs; + }, + // format date before writing to DB, bools work format: function format(attrs) { return this.fixDatesWhenSave(attrs);