Skip to content

where: a static field holding a chain of where queries keeps only the last one #17212

Backlog

Description

@borinquenkid

A static field or static property of a domain class that holds a chain of where queries keeps only the last one, and builds it on the class that holds the field:

@Entity
class Book {
    String title
    static recent = Author.where { name == 'x' }.where { age > 1 }
}

Book.recent is a query on Book with the restriction age > 1 only. The same chain written in a method queries Author with both restrictions. The unqualified form, where { ... }.where { ... }, loses all but the last query as well.

Seen on 7.2.x at a19d39f with the in-memory datastore.

Cause: the transform replaces the whole initial value of such a field with one criteria built from the last closure.

https://github.com/apache/grails-core/blob/a19d39f158/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/query/transform/DetachedCriteriaTransformer.java#L196-L230

Chains that hold another call, such as .max(5) or whereAny, or that start from a stored criteria, lose queries in the same way.

Reported by @sanjana2505006 in the review of #17184, which does not fix it.

Activity

  1. borinquenkid commented on Nov 28, 2026

    @borinquenkid
    MemberAuthor

    #17214 fixes chains of where and whereLazy. This issue stays open for chains with another call in them or from a stored criteria.

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

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions