Grails/ createccriteria -比较两个列表



通过使用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")
}

相关内容

  • 没有找到相关文章

最新更新