通过使用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")
}
答案 0 :(得分: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")
}