app2-api/modules/blog/category.model.js

35 lines
728 B
JavaScript
Raw Normal View History

2019-04-15 15:58:58 +00:00
module.exports = function (sequelize, DataTypes) {
const Category = sequelize.define('Category', {
id: {
type: DataTypes.INTEGER,
2019-05-09 16:23:54 +00:00
autoIncrement: true,
2019-04-15 15:58:58 +00:00
primaryKey: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
sort: {
type: DataTypes.INTEGER,
2019-05-23 09:40:50 +00:00
defaultValue: 0,
2019-05-09 16:23:54 +00:00
allowNull: false,
2019-04-15 15:58:58 +00:00
}
}, {
tableName: 'category',
freezeTableName: true,
timestamps: false
});
2019-05-23 09:40:50 +00:00
/*Category.beforeCreate((category) => {
2019-05-09 16:23:54 +00:00
//category.dataValues.id = Math.floor(Math.random() * (999 - 8)) + 8;
2019-05-23 09:40:50 +00:00
})*/
2019-04-15 15:58:58 +00:00
Category.associate = function (models) {
Category.Posts = Category.belongsToMany(models.Post, {
through: models.PostCategory,
foreignKey: 'categoryId'
});
};
return Category;
};