Grails/CreateCriteria - 比较两个列表
Grails/CreateCriteria - compare two lists
通过使用 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")
}
是的,您可以这样使用 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")
}
通过使用 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")
}
是的,您可以这样使用 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")
}