61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = app => {
|
|
const { BIGINT } = app.Sequelize;
|
|
|
|
const EmployeeRole = app.model.define('employee_role', {
|
|
id: {
|
|
type: BIGINT.UNSIGNED,
|
|
primaryKey: true,
|
|
autoIncrement: true,
|
|
comment: '主键ID',
|
|
},
|
|
employee_id: {
|
|
type: BIGINT.UNSIGNED,
|
|
allowNull: false,
|
|
comment: '员工ID',
|
|
},
|
|
role_id: {
|
|
type: BIGINT.UNSIGNED,
|
|
allowNull: false,
|
|
comment: '角色ID',
|
|
},
|
|
}, {
|
|
tableName: 'wms_employee_role', // 指定实际表名
|
|
timestamps: false, // 不自动添加 createdAt 和 updatedAt
|
|
comment: '员工角色关联表',
|
|
indexes: [
|
|
{
|
|
name: 'uk_employee_role',
|
|
unique: true,
|
|
fields: [ 'employee_id', 'role_id' ],
|
|
},
|
|
{
|
|
name: 'idx_employee_id',
|
|
fields: [ 'employee_id' ],
|
|
},
|
|
],
|
|
});
|
|
|
|
// 关联关系
|
|
EmployeeRole.associate = function() {
|
|
const { AccountStoreEmployee, Role } = app.model;
|
|
|
|
// 关联员工表
|
|
EmployeeRole.belongsTo(AccountStoreEmployee, {
|
|
foreignKey: 'employee_id',
|
|
targetKey: 'id',
|
|
as: 'employee',
|
|
});
|
|
|
|
// 关联角色表
|
|
EmployeeRole.belongsTo(Role, {
|
|
foreignKey: 'role_id',
|
|
targetKey: 'id',
|
|
as: 'role',
|
|
});
|
|
};
|
|
|
|
return EmployeeRole;
|
|
};
|