Skip to content

Group by is propagating to separated includes #9748

Closed

Description

@mjamado

What are you doing?

I have structures like this:

News » hasMany » NewsTranslations
News » hasMany » Sections » hasMany » SectionsTranslations

Sometimes I need the full structure, sometimes half, sometimes there's a where condition to the title of one of the translations. Bottom line is, I have semi-demi-ORM before the Sequelize ORM which builds (among other things) the necessary includes.

Because the findAndCountAll is sort of broken in v4 (I've heard it's fixed on v5, but can't upgrade on account of other stuff), I opted to separate: true the hasMany associations if and only if that association is not being used on where or order. If it is, I need to group by the main table primary key.

The problem arises because Sequelize applies that same group to the separate'd queries - which, of course, breaks them.

What do you expect to happen?

Not apply group to associations which are separate.

What is actually happening?

All hell breaks loose.

Suggestion

A simple modification to model.js on line 1681 works:

        // _.omit(options, 'include', 'attributes', 'order', 'where', 'limit', 'offset', 'plain'),
        _.omit(options, 'include', 'attributes', 'order', 'where', 'limit', 'offset', 'plain', 'group'),

But can it be done? Will it break something else for someone? Can it land on v4, or only for v5?

Activity

  1. added
    type: bug
    good first issue
    on Aug 1, 2018
  2. sushantdhiman commented on Aug 1, 2018

    @sushantdhiman
    Contributor

    Will accept PR with short test case

  3. mjamado commented on Aug 1, 2018

    @mjamado
    ContributorAuthor

    If somebody could pretty please include the pull request on v5.0.0-beta.11 and release it... 🙏

  4. sushantdhiman commented on Aug 2, 2018

    @sushantdhiman
    Contributor

    Thanks for the PR, fix will be released as 5.0.0-beta.11, may be this weekend :)

  5. mjamado commented on Aug 9, 2018

    @mjamado
    ContributorAuthor

    Any news on release date?

  6. sushantdhiman commented on Aug 9, 2018

    @sushantdhiman
    Contributor

    Sorry my main work laptop is out of commission, which contain Sequelize dev setup. I wanted to include a few more changes to new release, you will have to wait for a few more days.

    Meanwhile you can directly use sequelize/sequelize (for master branch) in your package.json

  7. mjamado commented on Aug 9, 2018

    @mjamado
    ContributorAuthor

    Wow, 5+ years of dealing with package.json and npm, didn't know that repository trick. Thanks a lot!

  8. tizzyapunkt commented on May 27, 2019

    @tizzyapunkt

    It seems that this issue still exists.
    I am on 5.8.6 and the GROUP BY clause gets added to the separate: true include.
    @mjamado, can you confirm that?

    UPDATE: I saw, that this is caused by the sequelize-view-support which uses an < 5 version of sequelize where the issue is not fixed at this point in time.

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

    good first issuetype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions