Skip number conversion on string fields

Fixes #1524
This commit is contained in:
David Thomas 2018-07-08 09:33:46 -04:00
parent aab2f3e06c
commit 6143c3e1ca

24
packages/strapi-utils/lib/models.js Executable file → Normal file
View File

@ -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);