var User = sequelize.define('User', {
_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
name: DataTypes.STRING,
email: {
type: DataTypes.STRING,
unique: {
msg: 'The specified email address is already in use.'
},
validate: {
isEmail: true
}
},
role: {
type: DataTypes.STRING,
defaultValue: 'user'
}
}
the model has some associations as follows:
User.belongsToMany(models.Skill, {through: 'UserSkill', as: 'Skills'});
to save a new record i use the following request payload:
{
"name": "Test User",
"email": "example@example.com",,
"skills" : [2,3]
}