I am using Sequelize ORM. how to set multiple columns in join table? for example -
const UsersTasks = sequelize.define('UsersTasks', {
id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },
userId: {
type: Sequelize.INTEGER,
references: {
model: User,
key: 'id',
},
},
remarks: { type: Sequelize.STRING(128), allowNull: true },
taskId: {
type: Sequelize.INTEGER,
references: {
model: Task,
key: 'id',
},
},
}, {
timestamps: false,
version: true,
});
User.belongsToMany(Task, {
through: {
model: UsersTasks,
unique: false,
},
foreignKey: 'userId',
as: 'task',
});
Task.belongsToMany(User, {
through: {
model: UsersTasks,
unique: false,
},
foreignKey: 'taskId',
});
How can create user - task relationships in UsersTasks?
User.setTask([1,2], {remarks: 'type1'}); User.setTask([1,3], {remarks: 'type2'});
Is this the right way to insert records as following?
id userId taskId remarks
1 1 1 'type1'
2 1 2 'type1'
3 1 1 'type2'
4 1 3 'type2'