Grails criteria select when hasMany hasn't any elements

空扰寡人 提交于 2020-01-02 23:26:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!