12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /* indent size: 2 */
- module.exports = app => {
- const DataTypes = app.Sequelize;
- const Model = app.model.define('ProductCategory', {
- category_id: {
- type: DataTypes.INTEGER(10).UNSIGNED,
- primaryKey: true,
- autoIncrement: true,
- },
- category_name: {
- type: DataTypes.STRING(255),
- allowNull: true,
- },
- pid: {
- type: DataTypes.INTEGER(10).UNSIGNED,
- allowNull: true,
- },
- category_image: {
- type: DataTypes.STRING(255),
- allowNull: true,
- },
- category_sort: {
- type: DataTypes.INTEGER(10).UNSIGNED,
- allowNull: true,
- },
- is_show: {
- type: DataTypes.INTEGER(1).UNSIGNED,
- allowNull: true,
- },
- is_nav: {
- type: DataTypes.INTEGER(1).UNSIGNED,
- allowNull: true,
- },
- category_attrs: {
- type: DataTypes.TEXT,
- allowNull: true,
- },
- admin_id: {
- type: DataTypes.INTEGER(10).UNSIGNED,
- allowNull: true,
- },
- update_time: {
- type: DataTypes.TIME,
- },
- create_time: {
- type: DataTypes.DATE,
- allowNull: true,
- },
- }, {
- tableName: 'szj_product_category',
- });
- Model.associate = function() {
- // 关联管理员表
- Model.belongsTo(app.model.AdminUser, { foreignKey: 'admin_id', targetKey: 'admin_id', as: 'admin_user' });
- // 关联商品
- Model.hasMany(app.model.Products, { foreignKey: 'category_id', targetKey: 'category_id', as: 'products' });
- };
- // 同步:没有就新建,有就不变
- Model.sync();
- return Model;
- };
|