Is there a 'contains' functionality on a collection property of a domain object for createCriteria?

混江龙づ霸主 提交于 2019-12-29 08:29:11

问题


I have an Auction domain object and a User domain object. An Auction hasMany Users.

What I'd like to do, using createCriteria, is something like this:

def c = Auction.createCriteria()
def l = c.list (max: maxVar, offset: offsetVar) {
    contains("users", thisUser)
}

Though, contains is not in the list of acceptable nodes: createCriteria description page.

Is there any way to implement this functionality?

To be clear, is there a way to have the criteria be that a specified User object is contained within a collection property of the Auction?


回答1:


Try this:

def l = c.list (max: maxVar, offset: offsetVar) {
    users {
        idEq(thisUser.id)
    }
}


来源:https://stackoverflow.com/questions/11475009/is-there-a-contains-functionality-on-a-collection-property-of-a-domain-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!