通过使用CreateCriteria,我想比较两个列表并检查groups
中是否至少有一个元素存在于users
中。是否有像eq
这样的东西来实现这一点?
class User {
String login
static hasMany = [groups = String]
}
class Project {
String name
static hasMany = [users = User]
}
CreateCriteria
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")
}
是的,你可以像这样使用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")
}