Q:

Grails- How to query the list

I have a domain classes like this
 Class Rules{
  List <Department> departments = new ArrayList<Department>()
  // blah blah 
  static hasMany = [departments:Department]
 }

  Class Department {
     String name
  }

def listOfRules= // find the rules based on department selected

i am trying to get all the Rules which contains selected departments  .. so how can i query that.. 
this is grails application.. which uses hibernate .

A:

List departmentIds = []
// Code to populate departmentIds goes here

def rulesWithTestingDepartment = Rules.withCriteria {
  departments {
    'in'('id', departmentIds)
  }
}

