Skip to content

group by on nested model causes invalid SQL #8726

Open

Description

@jharting

What are you doing?

Based on http://docs.sequelizejs.com/manual/tutorial/querying.html#ordering I can use order by clause such as:

order: [
  [Vehicle.associations.engine, Engine.associations.crankshaft, 'name']
]

Intuitively, I would expect the same syntax to work with group by also:

group: [
  [Vehicle.associations.engine, Engine.associations.crankshaft, 'name']
]

but that produces invalid SQL query.

What do you expect to happen?

The query uses group by with the nested model's attribute

What is actually happening?

Invalid SQL is produced:
SequelizeDatabaseError: Unknown column 'engine.crankshaft.name' in 'group statement'

The correct column name would be: engine->crankshaft.name

Dialect: mysql, sqlite
Sequelize version: 4.23.1
Tested with master branch: Yes

Activity

  1. jharting commented on Nov 30, 2017

    @jharting
    ContributorAuthor
  2. aGolduck commented on Jan 26, 2018

    @aGolduck
    Contributor

    I bypassed this issue by group: sequelize.col('engine->crankshaft.name'), hope for an official bug fix.

  3. cibergarri commented on Feb 5, 2018

    @cibergarri

    I have found the same issue, for me only works to write the name with the arrow in the column.
    group: sequelize.col('engine->crankshaft.name')

  4. stale commented on May 7, 2018

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

  5. added
    type: bug
    and removed on May 7, 2018
  6. hertz1 commented on Sep 16, 2018

    @hertz1

    +1
    I'm facing the same issue. Any news on this?

  7. edmsamuel commented on Jun 3, 2019

    @edmsamuel

    Hi, this issue was solved?

  8. pallatee commented on Sep 1, 2019

    @pallatee

    Still nothing on this?

  9. added
    docs
    on Sep 1, 2019
  10. added theissue type on Mar 9, 2025
  11. removed
    type: bug
    on Mar 9, 2025
  12. LeonxLJX commented on Sep 2, 2026

    @LeonxLJX
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

    docs

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions