Based this GORM Domain class:
class Component implements Serializable {
Long id
String name
Double total
Long parentComponentId
static mapping = {
...
}
static constraints = {
...
parentComponentId nullable: true
}
}
My questions are:
- How do we reference a Domain class to itself, on this case
parentComponentId
is another instance ofComponent
. - If that referencing problem in #1 is solved, how can I execute a query similar to this:
select a.*, b.* from COMPONENT a join COMPONENT b on a.id = b.parentComponentId group by a.id having sum(b.total) = a.total