Grails-如何查询列表

时间:2012-01-09 10:21:31

标签: grails groovy gorm

我有像这样的域类

 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

我正在尝试获取包含所选部门的所有规则..所以我该如何查询..

这是grails application ..它使用了hibernate。

1 个答案:

答案 0 :(得分:2)

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

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