From 6143c3e1ca59c710c47d73885dccbc2bc35bcbfd Mon Sep 17 00:00:00 2001 From: David Thomas Date: Sun, 8 Jul 2018 09:33:46 -0400 Subject: [PATCH] Skip number conversion on string fields Fixes #1524 --- packages/strapi-utils/lib/models.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) mode change 100755 => 100644 packages/strapi-utils/lib/models.js diff --git a/packages/strapi-utils/lib/models.js b/packages/strapi-utils/lib/models.js old mode 100755 new mode 100644 index 4f416be13a..7af0be329f --- a/packages/strapi-utils/lib/models.js +++ b/packages/strapi-utils/lib/models.js @@ -457,11 +457,25 @@ module.exports = { _.forEach(params, (value, key) => { let result; let formattedValue; - - // Check if the value if a valid candidate to be converted to a number value - formattedValue = isNumeric(value) - ? _.toNumber(value) - : value; + let modelAttributes = models[model]['attributes']; + let fieldType; + // Get the field type to later check if it's a string before number conversion + if (modelAttributes[key]) { + fieldType = modelAttributes[key]['type']; + } else { + let splitKey = key.split('_').pop(); + if (modelAttributes[splitKey]) { + fieldType = modelAttributes[splitKey]['type']; + } + } + // Check if the value is a valid candidate to be converted to a number value + if (fieldType != 'string') { + formattedValue = isNumeric(value) + ? _.toNumber(value) + : value; + } else { + formattedValue = value; + } if (_.includes(['_start', '_limit'], key)) { result = convertor(formattedValue, key);