开发者

In grails, why do I have to create a variable for criteria?

开发者 https://www.devze.com 2023-01-16 21:23 出处:网络
I can write: def c = Transaction.createCr开发者_运维知识库iteria() def transactions = c.list {

I can write:

def c = Transaction.createCr开发者_运维知识库iteria() 
def transactions = c.list {
    projections {
        groupProperty("product")
        countDistinct("id")
    }
    maxResults(pageBlock)
    firstResult(pageIndex)
}

But can't write this:

def transactions = Transaction.createCriteria() .list {
    projections {
        groupProperty("product")
        countDistinct("id")
    }
    maxResults(pageBlock)
    firstResult(pageIndex)
}

Why is this? Why is the variable c required for holding the criteria?


try using another name, not "transaction" and see if you get the desired results.

i took your code, and just changed the name of the objects and it works fine


Your second example should work as Aaron pointed out. Sometimes I found when there are no results from the DB then you get errors so maybe it's that.

list() is the default by the way, so if you really want to shorten it, you can even do this:

def transactions = Transaction.createCriteria() {
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号