Skip to content

Commit

Permalink
save assosiation data as integer id for mySql DB
Browse files Browse the repository at this point in the history
  • Loading branch information
stuk88 committed Nov 14, 2022
1 parent 193647b commit 4856141
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 4856141

Please sign in to comment.