Skip to content

Special method/mixin "add" for BelongsToMany association overrides record instead of creating a new one #16984

Open

Description

@rdsedmundo

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Bug Description

Reproducible Example

Here is the link to the SSCCE for this issue: rdsedmundo/20240123-sequelize-add-mixin-method-bug@af84fd6

What do you expect to happen?

A new record should have been created, especially because another field of the junction table is passed—although to be honest in any case I think I'd expect what is happening without an unique constraint being defined.

Setting through.unique to false doesn't change anything.

What is actually happening?

The third test is executing this:

[Sequelize] Executed (default): UPDATE FooBarAttachments SET restrictionId=$1 WHERE fooName = $2 AND barName = $3; {"$1":3,"$2":"TS foo","$3":"TS bar"} [Elapsed time: 0 ms]

Environment

  • Sequelize version: 6.11.0
  • Node.js version: 20.9.0
  • If TypeScript related: TypeScript version: 5.1.6
  • Database & Version: Postgres 16.1
  • Connector library & Version: 8.9.0

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

Activity

  1. added
    pending-approval
    type: bug
    on Jan 23, 2024
  2. added theissue type on Mar 9, 2025
  3. removed
    type: bug
    on Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-approval

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions