35 lines
728 B
JavaScript
Executable File
35 lines
728 B
JavaScript
Executable File
module.exports = function (sequelize, DataTypes) {
|
|
const Category = sequelize.define('Category', {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
autoIncrement: true,
|
|
primaryKey: true
|
|
},
|
|
name: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
sort: {
|
|
type: DataTypes.INTEGER,
|
|
defaultValue: 0,
|
|
allowNull: false,
|
|
}
|
|
}, {
|
|
tableName: 'category',
|
|
freezeTableName: true,
|
|
timestamps: false
|
|
});
|
|
|
|
/*Category.beforeCreate((category) => {
|
|
//category.dataValues.id = Math.floor(Math.random() * (999 - 8)) + 8;
|
|
})*/
|
|
|
|
Category.associate = function (models) {
|
|
Category.Posts = Category.belongsToMany(models.Post, {
|
|
through: models.PostCategory,
|
|
foreignKey: 'categoryId'
|
|
});
|
|
};
|
|
|
|
return Category;
|
|
}; |