Commit 33a985c165e1726addbb72640c58240dd5f07267

Authored by ly525
1 parent b583bf6f

fix(deploy heroku) could not save array as json field

back-end/h5-api/api/work/models/Work.js
@@ -7,7 +7,19 @@ @@ -7,7 +7,19 @@
7 module.exports = { 7 module.exports = {
8 // Before saving a value. 8 // Before saving a value.
9 // Fired before an `insert` or `update` query. 9 // Fired before an `insert` or `update` query.
10 - // beforeSave: async (model, attrs, options) => {}, 10 + beforeSave: async (model, attrs, options) => {
  11 + // https://github.com/strapi/strapi/issues/2882
  12 + // need to remove this after this pr will be merged(https://github.com/strapi/strapi/pull/3664)
  13 + Object.keys(model.constructor.attributes).forEach(k => {
  14 + if (model.constructor.attributes[k].type === 'json') {
  15 + const value = model.get(k);
  16 +
  17 + if (Array.isArray(value)) {
  18 + model.set(k, JSON.stringify(value));
  19 + }
  20 + }
  21 + });
  22 + },
11 23
12 // After saving a value. 24 // After saving a value.
13 // Fired after an `insert` or `update` query. 25 // Fired after an `insert` or `update` query.