0

通过使用 CreateCriteria,我想比较两个列表并groups检查users. 有类似eq的东西吗?

领域

class User {
    String login
    static hasMany = [groups = String]
} 

class Project {
    String  name
    static hasMany = [users = User]
}

创建标准

def UserInstance = User.get(1)

def idList =  Project.createCriteria().list () {

    projections { distinct ( "id" )
        property("name")
        property("id")
    }

    eq("users.login", UserInstance.groups) //check if there are at least one element in groups list present in users list.  
    order("name","desc")

}
4

1 回答 1

2

是的,您可以像这样使用inList(String propertyName, Collection c)

def UserInstance = User.get(1)

def idList =  Project.withCriteria {

    projections { 
        distinct("id")
        property("name")
        property("id")
    }

    users {
        inList("login", UserInstance.groups)
    }

    order("name","desc")
}
于 2015-10-07T18:52:23.260 回答