圣杯映射/排序关联



在我有的类中

static hasMany = [allocations: Allocations]

.. 和映射

static mapping = {
    allocations sort: 'line'
}

我想添加第二个排序字段..类似的东西

static mapping = {
    allocations sort: ['line', 'qty']
}

但我无法获得任何工作(尝试分配排序:([行:'asc',数量:'asc'](和其他(。是否可以以这种方式对多个属性上的关联进行排序?

顺便说一句,圣杯 2.3.7 ..

谢谢

不,不是。 sort() 仅允许您按单个属性进行排序。

自定义默认属性 [ <--singular] 以作为查询结果的排序依据。

https://grails.github.io/grails-doc/latest/ref/Database%20Mapping/sort.html

相反,您可以使用条件查询:

SomeDomain.withCriteria { 
    allocations {
        order('line')
        order('qty')
    }
}

最新更新