GRAILS: Find all children in a self-referenced one-to-many relationship

后端 未结 2 728
长情又很酷
长情又很酷 2021-01-01 06:08

In grails,

How would one find all the children in a one-to-many relationship e.g.,

class Employee {
    static hasMany = [ subordinates: Employee ]
          


        
2条回答
  •  生来不讨喜
    2021-01-01 06:32

     //Make a recursive closure
     def printAll
    
     printAll = { emp ->
        subordinates.each { 
                            println it
                            printAll emp
                          }
     }
    

提交回复
热议问题