Skip to content

fix(datamapping-core): a static field holding a chain of where queries keeps every query - #17214

Draft
borinquenkid wants to merge 2 commits into
fix/where-or-exists-alias-7.2.xfrom
fix/where-static-field-chain-7.2.x
Draft

borinquenkid wants to merge 2 commits into
fix/where-or-exists-alias-7.2.xfrom
fix/where-static-field-chain-7.2.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Stacked on #17184, which it needs. Part of #17212.

Problem

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

@Entity class Book {
    String title
    static recent = Author.where { name == 'x' }.where { age > 1 }   // a query on Book with age > 1 only
}

Change

The first query of a chain of where and whereLazy calls, from a class it names or unqualified, becomes the criteria the others add to. The field holds the whole chain, as a method does, and the class still loads without a datastore. The value is cast to the type of the field, which static type checking needs. A field is visited more than once, so a built chain is marked.

Chains with another call in them, such as max or whereAny, and chains that start from a stored criteria, still lose queries; #17212 stays open for them.

Results that change

A static field or property holding such a chain now returns the rows of the whole chain, on the class the first query names. To keep the previous result, write only the last query on the holding class. No setting: the old behaviour dropped queries the source writes and ran against a class it does not name. The upgrade note and the upgrade skill say so.

Tests

WhereQueryStaticFieldChainSpec runs the chains in a static field and a static property, dynamic and statically compiled. All 103 cases fail without the change, and 66 fail without the cast. grails-datamapping-core, grails-datamapping-core-test, the Hibernate 5 module, the MongoDB module and codeStyle pass.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

…s keeps every query

A static field or property holding Author.where { }.where { } kept only the last query, on the class that holds the
field. The first query of the chain becomes the criteria the others add to, on the class it names, and the value is
cast to the type of the field for static type checking.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant