product_category.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* indent size: 2 */
  2. module.exports = app => {
  3. const DataTypes = app.Sequelize;
  4. const Model = app.model.define('ProductCategory', {
  5. category_id: {
  6. type: DataTypes.INTEGER(10).UNSIGNED,
  7. primaryKey: true,
  8. autoIncrement: true,
  9. },
  10. category_name: {
  11. type: DataTypes.STRING(255),
  12. allowNull: true,
  13. },
  14. pid: {
  15. type: DataTypes.INTEGER(10).UNSIGNED,
  16. allowNull: true,
  17. },
  18. category_image: {
  19. type: DataTypes.STRING(255),
  20. allowNull: true,
  21. },
  22. category_sort: {
  23. type: DataTypes.INTEGER(10).UNSIGNED,
  24. allowNull: true,
  25. },
  26. is_show: {
  27. type: DataTypes.INTEGER(1).UNSIGNED,
  28. allowNull: true,
  29. },
  30. is_nav: {
  31. type: DataTypes.INTEGER(1).UNSIGNED,
  32. allowNull: true,
  33. },
  34. category_attrs: {
  35. type: DataTypes.TEXT,
  36. allowNull: true,
  37. },
  38. admin_id: {
  39. type: DataTypes.INTEGER(10).UNSIGNED,
  40. allowNull: true,
  41. },
  42. update_time: {
  43. type: DataTypes.TIME,
  44. },
  45. create_time: {
  46. type: DataTypes.DATE,
  47. allowNull: true,
  48. },
  49. }, {
  50. tableName: 'szj_product_category',
  51. });
  52. Model.associate = function() {
  53. // 关联管理员表
  54. Model.belongsTo(app.model.AdminUser, { foreignKey: 'admin_id', targetKey: 'admin_id', as: 'admin_user' });
  55. // 关联商品
  56. Model.hasMany(app.model.Products, { foreignKey: 'category_id', targetKey: 'category_id', as: 'products' });
  57. };
  58. // 同步:没有就新建,有就不变
  59. Model.sync();
  60. return Model;
  61. };