0

By using the CreateCriteria, I want to compare two lists and check if there are at least one element in groups present in users. Is there something like eq to perform that?

Domain

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")

}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
Jils
  • 783
  • 5
  • 12
  • 32

1 Answers1

2

Yes, you can use inList(String propertyName, Collection c) like this:

def UserInstance = User.get(1)

def idList =  Project.withCriteria {

    projections { 
        distinct("id")
        property("name")
        property("id")
    }

    users {
        inList("login", UserInstance.groups)
    }

    order("name","desc")
}
Emmanuel Rosa
  • 9,697
  • 2
  • 14
  • 20