67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = app => {
|
|
const { STRING, BIGINT, INTEGER } = app.Sequelize;
|
|
|
|
// 修改这里的变量名,与文件名一致
|
|
const PlatformSetting = app.model.define('platform_setting', {
|
|
id: {
|
|
type: INTEGER(11),
|
|
primaryKey: true,
|
|
autoIncrement: true,
|
|
allowNull: false,
|
|
comment: '主键ID',
|
|
},
|
|
platform_code: {
|
|
type: STRING(50),
|
|
allowNull: false,
|
|
comment: '平台代码',
|
|
},
|
|
code: {
|
|
type: STRING(50),
|
|
allowNull: false,
|
|
comment: '设置代码',
|
|
},
|
|
warehouse_id: {
|
|
type: BIGINT(20),
|
|
allowNull: false,
|
|
comment: '仓库ID',
|
|
},
|
|
}, {
|
|
tableName: 'wms_platfrom_setting',
|
|
freezeTableName: true,
|
|
timestamps: false,
|
|
comment: '平台设置表',
|
|
indexes: [
|
|
{
|
|
name: 'platform_code',
|
|
unique: true,
|
|
fields: [ 'platform_code', 'warehouse_id' ],
|
|
},
|
|
{
|
|
name: 'warehouse_id',
|
|
fields: [ 'warehouse_id' ],
|
|
},
|
|
],
|
|
});
|
|
// 定义关联关系
|
|
PlatformSetting.associate = function() {
|
|
const { Store, Platform } = app.model;
|
|
|
|
// 关联仓库
|
|
PlatformSetting.belongsTo(Platform, {
|
|
foreignKey: 'platform_code',
|
|
targetKey: 'code',
|
|
as: 'platform',
|
|
});
|
|
// 关联仓库
|
|
PlatformSetting.belongsTo(Store, {
|
|
foreignKey: 'warehouse_id',
|
|
targetKey: 'id',
|
|
as: 'warehouse',
|
|
});
|
|
};
|
|
// 返回正确的变量名
|
|
return PlatformSetting;
|
|
};
|