带投影的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)
预测{
groupProperty(a.id)
属性(a.firstName,firstName)
property(a.lastName,lastName)
property(a.emailAddress,email)
}
}
其中sharedDocuments的定义如下
class SharedDocuments {
用户作者
用户接收者
文档文件
}
我所看到的是sharedDocumentsInstanceList al方式只有投影中提到的最后一个属性。我可以在withCriteria中使用相同的查询,但我似乎放弃了自动分页的优点,因为withCriteria不会返回分页的pagedresultlist!
为了那些仍然有这个问题的人;除去列表方法中提供的 params
对象。因此,上面的条件查询变成了:
def sharedDocumentsInstanceList = SharedDocuments.createCriteria()。list {
createAlias('receiver ','r')
createAlias('author','a')
eq(r.id,session.uid)
预测{
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)
}
My Question is exactly like Grails Projections not returning all properties and not grouped
I have a following criteria
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")
}
}
Where sharedDocuments is defined as follows
class SharedDocuments {
Users author
Users receiver
Documents file
}
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!
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屋!