jamesfredley commented on code in PR #16773:
URL: https://github.com/apache/grails-core/pull/16773#discussion_r4390112788


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/AliasRegistry.java:
##########
@@ -46,33 +50,51 @@ public void realize(String alias, Expression<?> expression) 
{
         realizedExpressions.put(alias, expression);
     }
 
+    public boolean hasLocalDefinition(String alias) {
+        return definitions.containsKey(alias);
+    }
+
+    public boolean isExplicit(String alias) {
+        HibernateAlias def = definitions.get(alias);
+        if (def != null) {
+            return def.explicit();
+        }
+        if (realizedExpressions.containsKey(alias)) {
+            return true;
+        }
+        if (parent != null) {
+            return parent.isExplicit(alias);
+        }
+        return false;
+    }
+
     public boolean isDefined(String alias) {

Review Comment:
   `owner { address { eqProperty('city', 'owner.firstName') } }` should reject 
a city that is not the owner's name. The right-hand `owner` is an implicit 
parent alias, and this hides it. The comparison is then omitted, so the query 
returns rows it should not.
   
   Keep that alias visible in the same query. Please assert the mismatch 
returns no rows.



##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/JpaQueryContext.java:
##########
@@ -116,6 +133,9 @@ public void setParent(JpaQueryContext parent) {
 
     public void addFrom(String path, From<?, ?> from) {
         joinTracker.addJoin(path, from);
+        if (!isSubquery && parent != null) {

Review Comment:
   `homeAddress { country { ... } }` and `workAddress { country { ... } }` both 
join `country`. The second block reuses the first join, so both restrictions 
hit the home country.
   
   Keep a relative join on the block that made it, or qualify the propagated 
key with its path.



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