带有投影的 CreateCriteria 不会选择所有列 [英] CreateCriteria with projections does not select all columns
问题描述
我的问题很像Grails 投影未返回所有属性且未分组
我有以下条件
def sharedDocumentsInstanceList SharedDocuments.createCriteria().list(params){
createAlias('receiver', 'r')
createAlias('author', 'a')
eq("r.id",session.uid)
projections{
groupProperty("a.id")
property("a.firstName","firstName")
property("a.lastName","lastName")
property("a.emailAddress","email")
}
}
其中sharedDocuments定义如下
Where sharedDocuments is defined as follows
class SharedDocuments {
Users author
Users receiver
Documents file
}
我所看到的是 sharedDocumentsInstanceList 始终只有投影中提到的最后一个属性.我可以在withCriteria"中使用相同的查询,但我似乎失去了自动分页的常规优点,因为 withCriteria 不返回分页的分页结果列表!
What I have seen is that sharedDocumentsInstanceList always has only the last property mentioned in the projection. I can use the same query in "withCriteria" but I seem to loose the groovy goodness of automatic pagination with it because withCriteria does not return paged pagedresultlist!
推荐答案
为了那些仍然有这个问题的人;删除列表方法上提供的 params
对象.所以上面的条件查询变成:
For the sake of those still having this issue; Remove the provided params
object on the list method. So the criteria query above becomes:
def sharedDocumentsInstanceList = SharedDocuments.createCriteria().list {
createAlias('receiver', 'r')
createAlias('author', 'a')
eq("r.id",session.uid)
projections {
groupProperty("a.id")
property("a.firstName","firstName")
property("a.lastName","lastName")
property("a.emailAddress","email")
}
maxResults(params.max)
firstResult(params.offset)
order(params.sort, params.order)
}
这篇关于带有投影的 CreateCriteria 不会选择所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!