Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize create model with object type

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, ... } }

like image 725
Андрей Гузюк Avatar asked Mar 07 '23 16:03

Андрей Гузюк


1 Answers

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.

like image 199
simon.ro Avatar answered Mar 19 '23 10:03

simon.ro