From bfccaa8d2e4e203019e5788f7f3e4339cc728782 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Thu, 7 Mar 2019 12:17:21 +0100 Subject: [PATCH] Added db formatter for settings model refs #10582 - ensure we won't forward booleans to database - type TEXT will transform booleans to "0"/"1! --- core/server/models/settings.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/server/models/settings.js b/core/server/models/settings.js index 31ffb106a334..b011250359b9 100644 --- a/core/server/models/settings.js +++ b/core/server/models/settings.js @@ -100,6 +100,17 @@ Settings = ghostBookshelf.Model.extend({ }); }, + format() { + const attrs = ghostBookshelf.Model.prototype.format.apply(this, arguments); + + // @NOTE: type TEXT will transform boolean to "0" + if (_.isBoolean(attrs.value)) { + attrs.value = attrs.value.toString(); + } + + return attrs; + }, + parse() { const attrs = ghostBookshelf.Model.prototype.parse.apply(this, arguments);