Using Grails 1.2.2, I have domain classes like the following:
class Department {
String name
LegalRep legalRep
static constraints = {
legalRep(nullable: true)
}
...
}
Class LegalRep {
String name
...
}
So a Department may have a LegalRep, or it may not.
In a controller I'm using criteria to order the list:
def deptCriteria = Department.createCriteria()
def deptList = deptCriteria.list {
if(params.sort == 'legalRepName') {
legalRep {
order('name', 'asc')
}
}
}
This works fine as long as all of the Departments have a LegalRep. As soon as there is one Department with a null LegalRep I get a GRE "Cannot invoke method call() on a null object"
Any way to have the criteria order the null's at the top or bottom?
class Department {
String name
LegalRep legalRep
static constraints = {
legalRep(nullable: true)
}
...
}
Class LegalRep {
String name
...
}
So a Department may have a LegalRep, or it may not.
In a controller I'm using criteria to order the list:
def deptCriteria = Department.createCriteria()
def deptList = deptCriteria.list {
if(params.sort == 'legalRepName') {
legalRep {
order('name', 'asc')
}
}
}
This works fine as long as all of the Departments have a LegalRep. As soon as there is one Department with a null LegalRep I get a GRE "Cannot invoke method call() on a null object"
Any way to have the criteria order the null's at the top or bottom?