Permalink
Browse files

Partial fix for GRAILS-9280

  • Loading branch information...
1 parent d00ab50 commit 756ce5c4da82437209cdba7be0c41db68358faa3 @graemerocher graemerocher committed Sep 5, 2012
View
28 grails-datastore-gorm-test/src/test/groovy/grails/gorm/tests/WhereMethodSpec.groovy
@@ -112,7 +112,7 @@ class WhereMethodSpec extends GormDatastoreSpec {
def results = people.property("lastName").property('firstName').list()
then:"The correct results are returned"
- results == [["Simpson", "Simpson", "Simpson", "Simpson"], ["Homer", "Marge", "Bart", "Lisa"]]
+ results == [["Simpson", "Homer"], ["Simpson", "Marge"], ["Simpson", "Bart"], ["Simpson", "Lisa"]]
}
def "Test where with multiple property projections"() {
@@ -127,7 +127,7 @@ class WhereMethodSpec extends GormDatastoreSpec {
}.list()
then:"The correct results are returned"
- results == [["Simpson", "Simpson", "Simpson", "Simpson"], ["Homer", "Marge", "Bart", "Lisa"]]
+ results == [["Simpson", "Homer"], ["Simpson", "Marge"], ["Simpson", "Bart"], ["Simpson", "Lisa"]]
}
@@ -359,6 +359,21 @@ class WhereMethodSpec extends GormDatastoreSpec {
then:"the correct results are returned"
query.count() == 4
}
+
+ def "Test comparing property with single ended association"() {
+ given:"people and pets"
+ createPeopleWithPets()
+
+ when:"We query a property against the property of a single-ended association"
+ def query = getClassThatCallsWhere().doQuery()
+// def query = Pet.where {
+// name == owner.firstName
+// }
+
+ then:"the correct results are returned"
+ query.count() == 0
+ }
+
def "Test ilike operator"() {
given:"A bunch of people"
createPeople()
@@ -1431,12 +1446,11 @@ class CallMe {
Person.where(myDetachedCriteria)
}
+
def doQuery() {
- def age = 5
- def pets = []
- def query = Person.where {
- age > age && pets { age > 5}
- }
+ def query = Pet.where {
+ name == owner.firstName
+ }
}
View
8 ...rc/main/groovy/org/grails/datastore/gorm/query/transform/DetachedCriteriaTransformer.java
@@ -658,7 +658,7 @@ private ClassNode getPropertyType(String prop) {
private ClassNode getPropertyType(ClassNode classNode, String prop) {
Map<String, ClassNode> cachedProperties = cachedClassProperties.get(classNode.getName());
- if(cachedProperties != null) {
+ if(cachedProperties != null && cachedProperties.containsKey(prop)) {
return cachedProperties.get(prop);
}
ClassNode type = null;
@@ -670,6 +670,12 @@ private ClassNode getPropertyType(ClassNode classNode, String prop) {
if (methodNode != null) {
type = methodNode.getReturnType();
}
+ else {
+ FieldNode fieldNode = classNode.getDeclaredField(prop);
+ if(fieldNode != null) {
+ type = fieldNode.getType();
+ }
+ }
}
return type;
}

0 comments on commit 756ce5c

Please sign in to comment.