diff --git a/server/src/models/Robot.ts b/server/src/models/Robot.ts index a48b9af1..41e974f9 100644 --- a/server/src/models/Robot.ts +++ b/server/src/models/Robot.ts @@ -1,6 +1,8 @@ import { Model, DataTypes, Optional } from 'sequelize'; import sequelize from '../storage/db'; import { WorkflowFile, Where, What, WhereWhatPair } from 'maxun-core'; +import User from './User'; // Import User model +import Run from './Run'; interface RobotMeta { name: string; @@ -82,4 +84,9 @@ Robot.init( } ); +Robot.hasMany(Run, { + foreignKey: 'robotId', + as: 'runs', // Alias for the relation +}); + export default Robot; \ No newline at end of file diff --git a/server/src/models/User.ts b/server/src/models/User.ts index 5a3d552c..f7c22b5b 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -1,5 +1,6 @@ import { DataTypes, Model, Optional } from 'sequelize'; import sequelize from '../storage/db'; +import Robot from './Robot'; interface UserAttributes { id: number; @@ -79,4 +80,9 @@ User.init( } ); +User.hasMany(Robot, { + foreignKey: 'userId', + as: 'robots', // Alias for the relation + }); + export default User;