In this code I am writing the attributes and the options. At the end I am returning them in the method sequelize.define(). My problem is that I can not find a way to set relationship with other models using this method.
const { DataTypes } = require('sequelize');
module.exports = model;
function model(sequelize) {
const attributes ={
email: { type: DataTypes.STRING, allowNull: false },
passwordHash: { type: DataTypes.STRING, allowNull: false },
username: { type: DataTypes.STRING, allowNull: false },
firstName: { type: DataTypes.STRING, allowNull: false },
lastName: { type: DataTypes.STRING, allowNull: false },
mobile:{type: DataTypes.INTEGER(11), allowNull: false},
role: { type: DataTypes.STRING, allowNull: false }
}
const options = {
defaultScope: {
attributes: { exclude: ['passwordHash'] }
},
scopes: {
withHash: { attributes: {}, },
}
};
return sequelize.define('User', attributes, options);
}