sequelize-typescript
sequelize-typescript copied to clipboard
I'm not getting a way to remove an association between these two models below:
I'm not getting a way to remove an association between these two models below:
@Table
class Ticket extends Model {
@PrimaryKey
@AutoIncrement
@Column
id: number;
@ForeignKey(() => Queue)
@Column
queueId: number;
@BelongsTo(() => Queue)
queue: Queue;
}
@Table
class Queue extends Model {
@PrimaryKey
@AutoIncrement
@Column
id: number;
}
To associate a Queue to a Ticket I do the following:
const queueId = 1;
await Ticket.findByPk(ticket.id).then(async ticket => {
await ticket.update({
queueId
});
ticket.reload();
});
Any ideas on how to remove this association?
Originally posted by @engmsilva in https://github.com/RobinBuschmann/sequelize-typescript/issues/774#issuecomment-1004261081
Setting their queueId to null should do it:
await ticket.update({
queueId: null
});