borinquenkid commented on PR #16773:
URL: https://github.com/apache/grails-core/pull/16773#issuecomment-6513030252

   Updated and rebased on `8.0.x`.
   
   The issue with dotted association properties in sibling blocks (such as 
`homeAddress { eq('country.name', 'USA') }` and `workAddress { 
eq('country.name', 'Canada') }`) was caused by `JpaQueryContext.registerAlias` 
unconditionally propagating realized aliases to `parent.registerAlias(...)` for 
non-subquery contexts. When `homeAddress` realized the implicit `country` 
alias, it was registered on the root query context, causing subsequent sibling 
blocks like `workAddress` to resolve `country` from the parent rather than 
creating an independent join on their own association path.
   
   In `JpaQueryContext.registerAlias`, propagation to the parent context is now 
restricted strictly to explicit aliases:
   ```java
   public void registerAlias(String alias, Expression<?> expression) {
       aliasRegistry.realize(alias, expression);
       if (!isSubquery && parent != null && aliasRegistry.isExplicit(alias)) {
           parent.registerAlias(alias, expression);
       }
   }
   ```
   
   Only explicit user-declared aliases propagate upward, ensuring implicit 
association navigation aliases remain scoped to their declaring block whether 
written as nested association closures or dotted property expressions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to