From 48561419e33115e80c807427b109531055c3995c Mon Sep 17 00:00:00 2001 From: Stas Arshanski Date: Mon, 14 Nov 2022 17:13:07 +0200 Subject: [PATCH] save assosiation data as integer id for mySql DB --- index.js | 8 ++++++-- package.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 75955e4..b3826a0 100644 --- a/index.js +++ b/index.js @@ -204,8 +204,12 @@ module.exports = function (sails) { if (sails.models[req.params.model]._attributes[key].type == "objectid") fields[key] = ObjectId(value); - if (typeof sails.models[req.params.model]._attributes[key].collection != "undefined" && !Array.isArray(fields[key])) - fields[key] = [fields[key]]; + if (typeof sails.models[req.params.model]._attributes[key].collection != "undefined" && !Array.isArray(fields[key])) { + if(sails.config.connections[sails.models[req.params.model].connection].adapter == 'sails-mysql') + fields[key] = fields[key] == "" ? [] : [parseInt(fields[key])]; + else + fields[key] = [fields[key]]; + } if (sails.models[req.params.model]._attributes[key].type == "date") fields[key] = moment(value, "MM-DD-YYYY").toDate(); diff --git a/package.json b/package.json index a304cf6..29b0892 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sails-hook-cms", - "version": "0.0.27", + "version": "0.0.29", "description": "A simple sails v0.12 admin panel", "main": "index.js", "scripts": {