Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm not getting a way to remove an association between these two models below: #1188

Open
engmsilva opened this issue Jan 17, 2022 · 1 comment

Comments

@engmsilva
Copy link

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 #774 (comment)

@ephys
Copy link
Member

ephys commented Apr 7, 2022

Setting their queueId to null should do it:

await ticket.update({
  queueId: null
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants