Reputation: 2164
Is this possible to create model with sequelize to look like:
var User = sequelize.define('User', {
username: DataTypes.STRING,
email: DataTypes.STRING,
password: DataTypes.STRING,
facebook: {
id: DataTypes.STRING,
token: DataTypes.STRING,
email: DataTypes.STRING,
name: DataTypes.STRING
},
})
Idea is: When i will get user data from DB i would like to see
User: {
facebook: {
id,
token,
...
}
}
Upvotes: 4
Views: 5433
Reputation: 1
Column dataType - TEXT save as JSON format after 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
})
Upvotes: 0
Reputation: 3312
No.
Either
User.facebook
a DataType.JSON
field (which is supported by postgresql only)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.
Upvotes: 8