使用DetachedCriteria对关联的域对象进行排序

时间:2015-05-26 08:42:33

标签: grails gorm

拥有这样的域模型:

package com
class Bar {
    String barName
}  

package com
class Foo {

    static belongsTo = [bar: Bar]

    String fooName
    Integer fooAge

}

我能够构建以下标准,一些上下文:(grails list.gsp / g:sortableColumn: being able to sort on associated domain objects):

   params.sort = 'bar.barName'
   def foos = Foo.createCriteria().list(params){
        gt 'fooAge', 10
   }

但使用DetachedCriteria时失败:

    params.sort = 'bar.barName'
    def foos =  new DetachedCriteria(Foo).build {
        gt 'fooAge', 10
    }.list(params)

异常:

could not resolve property: bar.barName of: com.Foo. Stacktrace follows:
Message: could not resolve property: bar.barName of: com.Foo
    Line | Method
->>   87 | initialize    in grails.gorm.PagedResultList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     50 | getTotalCount in     ''
|     26 | $tt__index .  in com.FooController$$EPB9xU8u
|    198 | doFilter      in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . .  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker     in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run           in java.lang.Thread

有解决方法吗?

0 个答案:

没有答案