我有两个名为IpPatient,Ward的域类,如下所示。
class IpPatient {
String ipRegNo
Ward ward
static constraints = {
ward nullable:true
ipRegNo nullable:false
}
}
class Ward
{
String name;
static constraints = {
name nullable:true
}
}
现在我想创建类似的条件
def criteria=IpPatient.createCriteria()
return criteria.list(max:max , offset:offset) {
order("ward.name","asc")
createAlias('ward', 'ward', CriteriaSpecification.LEFT_JOIN)
}
目前
IpPatient
表有13条记录,其中IpPatient
8条记录没有病房,因为病房可以为空。当我用
wardName
排序时,我得到5条包含病房的记录。在对可为空的内部对象进行排序之后,我需要一个条件来获取所有元素。
最佳答案
您可能没有在寻找基于HQL的方法,但这应该可以解决问题:
IpPatient.findAll("from IpPatient as i left outer join i.ward as w order by w.name asc")
关于grails - 在对可为空的内部对象进行排序之后,我需要一个常规的条件来获取所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13066923/