我喜欢新的Grails 2.0“,其中”查询但需要进行投影。谁知道怎么样?现在我有代码实例化所有域实例并提取我需要的字段:
List<Double> eloRatings = User.where { !deleted }.list()*.eloRating
这不是很有效。
答案 0 :(得分:10)
从this blog post开始,您无法使用where
查询直接使用投影。但是,由于where
查询中返回的对象是DetachedCriteria
,您可以为其添加传统条件,如下所示:
List<Double> eloRatings = User.where { !deleted }.projections {
property 'eloRating'
}.list()
这应该可行,我在Grails 2.0下进行了测试。