【问题标题】:grails query on nested attributes without criteria builder没有标准构建器的嵌套属性的grails查询
【发布时间】:2012-11-06 04:25:13
【问题描述】:

我的 grails 应用有以下类

class Person {
    Address address
    // other attributes
}

class Address {
    String street
    City city
    // more attributes
}

我想按街道名称的字母顺序查询前 5 个人。目前我正在做类似的事情

def criteria = Person.createCriteria();
def people = criteria.list(max:5) {
    address {
       order("street","asc")
    }
}

这行得通。我只是想知道是否有更短的方法可以做到这一点(可能没有标准生成器)。

【问题讨论】:

    标签: grails nested grails-orm hibernate-criteria


    【解决方案1】:

    实际上我认为这是最清晰和最有效的方法。你可以试试executeQuery 之类的东西,但老实说,我不确定这是否不那么冗长。如果你只是想缩短代码,你可以简化前两行:

    def people = Person.createCriteria().list(max:5) {
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-05
      • 2021-08-26
      相关资源
      最近更新 更多