Browse Source

Fix JSON parse error when fetching data from database

pull/6/head
Menci 6 years ago
parent
commit
08b9954a94
  1. 2
      models/common.js

2
models/common.js

@ -31,7 +31,7 @@ class Model {
let model = this.getModel(); let model = this.getModel();
let obj = JSON.parse(JSON.stringify(this.record.get({ plain: true }))); let obj = JSON.parse(JSON.stringify(this.record.get({ plain: true })));
for (let key in obj) { for (let key in obj) {
if (model.tableAttributes[key].type instanceof Sequelize.JSON) { if (model.tableAttributes[key].type instanceof Sequelize.JSON && typeof obj[key] === 'string') {
try { try {
this[key] = JSON.parse(obj[key]); this[key] = JSON.parse(obj[key]);
} catch (e) { } catch (e) {

Loading…
Cancel
Save