product_spes.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* indent size: 2 */
  2. 'use strict';
  3. module.exports = app => {
  4. const DataTypes = app.Sequelize;
  5. const Model = app.model.define('ProductSpes', {
  6. spe_id: {
  7. type: DataTypes.INTEGER(10).UNSIGNED,
  8. primaryKey: true,
  9. autoIncrement: true,
  10. },
  11. product_id: {
  12. type: DataTypes.INTEGER(10).UNSIGNED,
  13. allowNull: false,
  14. },
  15. item_id: {
  16. type: DataTypes.INTEGER(10).UNSIGNED,
  17. allowNull: false,
  18. },
  19. spes_value: {
  20. type: DataTypes.STRING(255),
  21. allowNull: true,
  22. },
  23. admin_id: {
  24. type: DataTypes.INTEGER(10).UNSIGNED,
  25. allowNull: true,
  26. },
  27. update_time: {
  28. type: DataTypes.TIME,
  29. allowNull: true,
  30. },
  31. create_time: {
  32. type: DataTypes.DATE,
  33. allowNull: true,
  34. },
  35. }, {
  36. tableName: 'szj_product_spes',
  37. });
  38. Model.associate = function() {
  39. // 关联管理员表
  40. Model.belongsTo(app.model.AdminUser, { foreignKey: 'admin_id', targetKey: 'admin_id', as: 'admin_user' });
  41. // 关联商品类型属性表
  42. Model.belongsTo(app.model.ProductTypesItem, {
  43. foreignKey: 'item_id',
  44. targetKey: 'item_id',
  45. as: 'product_types_item',
  46. });
  47. };
  48. // 同步:没有就新建,有就不变
  49. Model.sync();
  50. return Model;
  51. };