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

Allow $set null (remove association) #774

Merged
merged 5 commits into from
Jan 24, 2021
Merged

Conversation

Antiavanti
Copy link
Contributor

Referring to the documentation, use of null for relation $set() should be allowed.
https://sequelize.org/v5/manual/associations.html#associating-objects

// project is associated with task1 and task2
task2.setProject(null).then(() => {
  // and it's gone
})

@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #774 (1c7e980) into master (6b1e3ff) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #774   +/-   ##
=======================================
  Coverage   95.20%   95.20%           
=======================================
  Files         117      117           
  Lines        1126     1126           
  Branches      129      129           
=======================================
  Hits         1072     1072           
  Misses         22       22           
  Partials       32       32           
Impacted Files Coverage Δ
src/model/model/model.ts 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b1e3ff...1c7e980. Read the comment docs.

@theoludwig theoludwig merged commit ffe1c78 into sequelize:master Jan 24, 2021
@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?

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

Successfully merging this pull request may close these issues.

5 participants