Skip to content

Instantly share code, notes, and snippets.

@THEozmic
Created March 27, 2019 04:18
Show Gist options
  • Save THEozmic/9f15dcc79a86f01718fb1cc0a11e2da6 to your computer and use it in GitHub Desktop.
Save THEozmic/9f15dcc79a86f01718fb1cc0a11e2da6 to your computer and use it in GitHub Desktop.
export default (sequelize, DataTypes) => {
const Groups = sequelize.define('Groups', {
name: {
allowNull: false,
type: DataTypes.STRING,
validate: {
notEmpty: true
}
},
desc: {
allowNull: false,
type: DataTypes.STRING,
defaultValue: 'no description'
},
admin: {
allowNull: false,
type: DataTypes.INTEGER,
validate: {
notEmpty: true
}
}
});
Groups.associate = (models) => {
Groups.belongsToMany(models.Users, {
through: 'GroupUsers',
as: 'users',
foreignKey: 'groupId'
});
};
return Groups;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment