Skip to content

Missing data when querying for data with associated model using separate: true #14805

Open

Description

@konradgaca

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

When there is a many to many association between data in two tables/models and the junction table has a compound primary key there is an issue with data being lost for the associated model when using findAll with separate: true.
The ids of the junction table when appended as a string no longer form a unique id in _groupJoinData function in lib/dialects/abstract/query.js. As a result data for the associated model is dropped when grouping the results.

Reproducible Example

Here is the link to the SSCCE for this issue: sequelize/sequelize-sscce#231

What do you expect to happen?

I would expect that when using findAll and including an associated model with separate: true the associated data will be returned for all instances that have been found. In the example provided both Tasks should have one associated TaskCountry returned as a result of the findAll query.

What is actually happening?

When _groupJoinData groups the results it considers some of them as duplicates and drops them. This results in data missing in the results of the query. In the example provided one of the associated TaskCountries has been dropped and is missing in the result of the findAll.

Environment

  • Sequelize version: 6.21.3
  • Node.js version: 14.17.6
  • If TypeScript related: TypeScript version: 4.5.5
  • Database & Version: PostgreSQL 10
  • Connector library & Version: 8.7.3

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. github-actions commented on Aug 10, 2022

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

  2. konradgaca commented on Aug 19, 2022

    @konradgaca
    Author

    Bump up as it is still an issue.

  3. harsh-lamba commented on Aug 23, 2022

    @harsh-lamba

    Same with me.

  4. added
    type: bug
    on Aug 23, 2022
  5. added theissue type on Mar 9, 2025
  6. 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

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions