1
This commit is contained in:
49
config/model.associations.js
Normal file
49
config/model.associations.js
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 数据模型关联配置
|
||||
* 定义各个模型之间的关系(一对一、一对多、多对多)
|
||||
*/
|
||||
|
||||
module.exports = (models) => {
|
||||
// 示例: 用户和账户关联
|
||||
// if (models.pla_account && models.sys_user) {
|
||||
// models.pla_account.belongsTo(models.sys_user, {
|
||||
// foreignKey: 'user_id',
|
||||
// as: 'user'
|
||||
// });
|
||||
// models.sys_user.hasMany(models.pla_account, {
|
||||
// foreignKey: 'user_id',
|
||||
// as: 'accounts'
|
||||
// });
|
||||
// }
|
||||
|
||||
// 示例: 职位和任务状态关联
|
||||
if (models.job_postings && models.task_status) {
|
||||
models.job_postings.hasMany(models.task_status, {
|
||||
foreignKey: 'job_id',
|
||||
as: 'tasks'
|
||||
});
|
||||
models.task_status.belongsTo(models.job_postings, {
|
||||
foreignKey: 'job_id',
|
||||
as: 'job'
|
||||
});
|
||||
}
|
||||
|
||||
// 任务状态和任务指令关联(已禁用,不在数据库层面添加外键约束)
|
||||
// if (models.task_status && models.task_commands) {
|
||||
// models.task_status.hasMany(models.task_commands, {
|
||||
// foreignKey: 'task_id',
|
||||
// as: 'commands'
|
||||
// });
|
||||
// models.task_commands.belongsTo(models.task_status, {
|
||||
// foreignKey: 'task_id',
|
||||
// as: 'task'
|
||||
// });
|
||||
// }
|
||||
|
||||
// 在这里添加更多模型关联
|
||||
// 一对一: hasOne / belongsTo
|
||||
// 一对多: hasMany / belongsTo
|
||||
// 多对多: belongsToMany
|
||||
|
||||
console.log('模型关联配置完成');
|
||||
};
|
||||
Reference in New Issue
Block a user