oms/backend/app/model/principalUser.js

29 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 主体用户关联模型,对应 principal_users 表
* @param {Egg.Application} app egg application
* @return {object} principalUser model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize;
const PrincipalUser = app.model.define('principal_user', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '主体ID' },
user_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '用户ID' },
role: { type: STRING(50), comment: '该主体下的角色标识' },
is_default: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '是否默认主体:1是 0否' },
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1启用 0禁用' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
PrincipalUser.associate = () => {
app.model.PrincipalUser.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' });
app.model.PrincipalUser.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
};
return PrincipalUser;
};