[英]Grails/CreateCriteria - compare two lists
By using the CreateCriteria, I want to compare two lists and check if there are at least one element in groups
present in users
. 通过使用CreateCriteria,我想比较两个列表,并检查users
groups
是否存在至少一个元素。 Is there something like eq
to perform that? 是否有像eq
这样的东西执行?
Domain 域
class User {
String login
static hasMany = [groups = String]
}
class Project {
String name
static hasMany = [users = User]
}
CreateCriteria 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")
}
Yes, you can use inList(String propertyName, Collection c) like this: 是的,您可以像这样使用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")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.