feat: user and robot relation

This commit is contained in:
karishmas6
2024-10-21 19:50:15 +05:30
parent 413a11dd2c
commit 23c7b32372
2 changed files with 13 additions and 0 deletions

View File

@@ -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;

View File

@@ -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;