Sequelize create model with object type Sequelize create model with object type postgresql postgresql

Sequelize create model with object type


No.

Either

  1. you make User.facebook a DataType.JSON field (which is supported by postgresql only)
  2. you create an Entity 'facebook', which is 1:1 related to User

Option i) is fine, but you don't get any support from sequelize to check integrity and validity if you make it a json field.


Column dataType - TEXT save as JSON formatafter find table - return json patse text

PodPodMaterial.afterFind(async (material) => {  if(material.length) {    for(let mat in material) {      try {          material[mat].ez_kolvo = JSON.parse(material[mat].ez_kolvo)      } catch(e) {console.error(e)}    }  } else {    try {        material.ez_kolvo = JSON.stringify(material.ez_kolvo)    }catch(e) {console.error(e)}  }  return material})