Skip to content

Instantly share code, notes, and snippets.

@THEozmic
Last active July 17, 2017 11:59
Show Gist options
  • Save THEozmic/c1c74e41671922f99ff022a997806785 to your computer and use it in GitHub Desktop.
Save THEozmic/c1c74e41671922f99ff022a997806785 to your computer and use it in GitHub Desktop.
export default (sequelize, DataTypes) => {
const Users = sequelize.define('Users', {
username: {
allowNull: false,
type: DataTypes.STRING,
unique: true,
validate: {
notEmpty: true
}
},
phone: {
allowNull: false,
type: DataTypes.STRING,
validate: {
not: ['[a-z]', 'i']
}
},
email: {
allowNull: false,
type: DataTypes.STRING,
unique: true,
validate: {
isEmail: true
}
},
password: {
allowNull: false,
type: DataTypes.STRING,
validate: {
notEmpty: true
}
}
});
Users.associate = (models) => {
Users.belongsToMany(models.Groups, {
through: 'GroupUsers',
as: 'groups',
foreignKey: 'userId'
});
};
return Users;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment