File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
java/org/codehaus/groovy/grails/orm/hibernate/cfg
test/org/codehaus/groovy/grails/orm/hibernate Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -181,7 +181,8 @@ class NamedCriteriaProxy {
181181 def nextInChain = domainClass. metaClass. getMetaProperty(methodName). getProperty(domainClass)
182182 nextInChain. previousInChain = this
183183 return nextInChain(args)
184- } else if (domainClass. metaClass. getMetaProperty(methodName)) {
184+ } else if (domainClass. metaClass. getMetaProperty(methodName) &&
185+ ! Collection . isAssignableFrom(domainClass. metaClass. getMetaProperty(methodName). type)) {
185186 def nestedCriteria = domainClass. metaClass. getMetaProperty(methodName). getProperty(domainClass). criteriaClosure. clone()
186187 nestedCriteria. delegate = queryBuilder
187188 nestedCriteria(* args)
Original file line number Diff line number Diff line change @@ -7,6 +7,29 @@ class NamedCriteriaTests extends AbstractGrailsHibernateTests {
77
88 protected void onSetUp () {
99 gcl. parseClass('''
10+ class PlantCategory {
11+ Long id
12+ Long version
13+ Set plants
14+ String name
15+
16+ static hasMany = [plants:Plant]
17+
18+ static namedQueries = {
19+ withPlantsInPatch {
20+ plants {
21+ eq 'goesInPatch', true
22+ }
23+ }
24+ }
25+ }
26+
27+ class Plant {
28+ Long id
29+ Long version
30+ boolean goesInPatch
31+ String name
32+ }
1033
1134class Publication {
1235 Long id
@@ -70,6 +93,23 @@ class Publication {
7093''' )
7194 }
7295
96+ void testNamedQueryWithRelationshipInCriteria () {
97+ def plantCategoryClass = ga. getDomainClass(" PlantCategory" ). clazz
98+
99+ assert plantCategoryClass. newInstance(name :" leafy" )
100+ .addToPlants(goesInPatch :true , name :" lettuce" )
101+ .save(flush :true )
102+
103+ assert plantCategoryClass. newInstance(name :" grapes" )
104+ .addToPlants(goesInPatch :false , name :" white" )
105+ .save(flush :true )
106+
107+ session. clear()
108+
109+ def results = plantCategoryClass. withPlantsInPatch. list()
110+ assertEquals 1 , results. size()
111+ assertEquals ' leafy' , results[0 ]. name
112+ }
73113
74114 void testFindAllWhereAttachedToChainedNamedQueries () {
75115 def publicationClass = ga. getDomainClass(" Publication" ). clazz
You can’t perform that action at this time.
0 commit comments