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


##########
grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/query/criteria/AbstractDetachedCriteria.groovy:
##########
@@ -872,7 +872,14 @@ abstract class AbstractDetachedCriteria<T> implements 
Criteria, Cloneable {
     @CompileStatic
     AbstractDetachedCriteria<T> clone() {
         AbstractDetachedCriteria criteria = newInstance()
-        criteria.@criteria = new ArrayList(this.criteria)
+        Map<DetachedAssociationCriteria, DetachedAssociationCriteria> 
associationCopies = new IdentityHashMap<>()
+        List<Query.Criterion> clonedCriteria = new 
ArrayList<>(this.criteria.size())
+        for (Query.Criterion criterion : this.criteria) {
+            clonedCriteria.add(criterion instanceof 
DetachedAssociationCriteria ?
+                    copyAssociationCriteria((DetachedAssociationCriteria) 
criterion, associationCopies) : criterion)

Review Comment:
   An or block that aliases books and checks genre, followed by buildLazy { 
createAlias('books', 'b').eq('title', 'wanted') }, returns authors whose book 
title is not wanted. The junction still holds the original association, and the 
map holds a separate copy. Clone the association inside the junction with the 
same identity map, so the restriction lands on the node the query runs.



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