refactor(模型关系): 重构模型关联关系定义位置,从模型文件移至路由文件

This commit is contained in:
zhang1106
2026-03-12 11:19:56 +08:00
parent 2e87654c98
commit 668ea073e6
17 changed files with 1478 additions and 553 deletions
-8
View File
@@ -1,7 +1,5 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const Device = require('./Device');
const NetworkCard = require('./NetworkCard');
const DevicePort = sequelize.define('DevicePort', {
portId: {
@@ -67,10 +65,4 @@ const DevicePort = sequelize.define('DevicePort', {
]
});
DevicePort.belongsTo(Device, { foreignKey: 'deviceId', as: 'device' });
Device.hasMany(DevicePort, { foreignKey: 'deviceId', as: 'ports' });
DevicePort.belongsTo(NetworkCard, { foreignKey: 'nicId', as: 'networkCard' });
NetworkCard.hasMany(DevicePort, { foreignKey: 'nicId', as: 'ports' });
module.exports = DevicePort;