grails - 在对可为空的内部对象进行排序之后,我需要一个常规的条件来获取所有元素

标签 grails

我有两个名为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/

相关文章:

java - 我如何检查字符串是否是 Groovy 中的 IP?

rest - 如何将 CORS 与 grails rest API 一起使用?

grails - 在 Grails 中指定插件的顺序

tomcat - 如何在 Tomcat7 中部署 Grails 3.0.1 war 文件?

grails - 将密码哈希从 SHA 转换为 bcrypt

grails - 通过gradle任务传递grails run-app的命令行参数

grails - 使用变量访问Grails Holders中的配置

hibernate - GORM/hibernate :将标准加入(转换)到属性(property)的 child 的准则

Grails 命令对象未绑定(bind)到 'def' 类型

grails - 使用Grails 3将响应从长时间运行的流程返回给客户端