开发者

Grails GORM count function in a named query

开发者 https://www.devze.com 2023-03-19 08:39 出处:网络
I\'m writing some named queries for my domain classes in Grails and I\'ve hit a blocker. Given the following domain class:

I'm writing some named queries for my domain classes in Grails and I've hit a blocker.

Given the following domain class:

class Contributor {
    // evals is a collection of another domain class
    def evals

    static namedQueries = {
        hasNoEvals {
            // Something like this...
  开发者_运维百科          evals.size() == 0
        }
    }
}

Can anyone help with the syntax I need to select the Contributors who have no Evals?

Thanks.


Please look in createCriteria doc for "collection property" operations. In your case, it is isEmpty:

static namedQueries = {
    hasNoEvals {
        isEmpty('evals')
    }
}

For generic size restriction, it is sizeEq, sizeLe and so on.

0

精彩评论

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