当hasMany没有任何元素时,选择Grails标准 [英] Grails criteria select when hasMany hasn't any elements
本文介绍了当hasMany没有任何元素时,选择Grails标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类:
class Course {
字符串名称
static hasMany = [
studentGrades:StudentGrade
]
}
class StudentGrade {
字符串名称
int等级
}
如何在没有任何学生成绩的情况下制定一个标准来获得课程?
isEmpty 标准方法:
def c = Course.createCriteria()
def results = c.list {
isEmpty(studentGrades)
}
请参阅 docs 了解更多信息。
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?
解决方案
You could use the isEmpty
criterion method:
def c = Course.createCriteria()
def results = c.list {
isEmpty("studentGrades")
}
See the docs for further informations.
这篇关于当hasMany没有任何元素时,选择Grails标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文