Skip to content

Many-to-many queries followed by sorting raise exception when sorting is done by queried table properties #14636

Closed

Description

@helgew

The title (as convoluted as it is) probably says it all. The issue is demonstrated in this example app, specifically by the included test case. Briefly, when a simple where query is performed using a domain class that represents a many-to-many relationship between two other domain classes, sorting by the queried table requires that aliases are created for each table.

Activity

  1. self-assigned this
    on Mar 7, 2018
  2. removed their assignment
    on Jul 10, 2018
  3. jamesfredley commented on Feb 26, 2026

    @jamesfredley
    Contributor

    This issue has been verified as fixed in Grails 7.x / GORM 8.x.

    We wrote a reproduction test that exercises the exact scenario (many-to-many where query followed by sorting on queried table properties) and it passes on the current 7.0.x codebase. The fix was part of commit ddae6ee795 which auto-creates aliases for joined association projections.

    If you are still experiencing this issue on Grails 7.x, please reopen with a minimal reproduction.

  4. jamesfredley commented on Jul 24, 2026

    @jamesfredley
    Contributor

    Thanks for the report. The many-to-many where query with sorting across user.username is now covered by the issue-specific WhereQueryIssueVerificationSpec. The fix and regression coverage landed through PR #15460, shipped in Grails 7.0.8, and remain in current 8.0.x. Closing this as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions