问题
I have the classes:
class Course{
String name
static hasMany = [
studentGrades: StudentGrade
]
}
class StudentGrade{
String name
int grade
}
How can I make a criteria to get the courses without any student grade?
回答1:
You could use the isEmpty
criterion method:
def c = Course.createCriteria()
def results = c.list {
isEmpty("studentGrades")
}
See the docs for further informations.
来源:https://stackoverflow.com/questions/10429023/grails-criteria-select-when-hasmany-hasnt-any-elements