【发布时间】:2015-08-05 06:21:21
【问题描述】:
基于这个 GORM 域类:
class Component implements Serializable {
Long id
String name
Double total
Long parentComponentId
static mapping = {
...
}
static constraints = {
...
parentComponentId nullable: true
}
}
我的问题是:
- 在这种情况下,我们如何将域类引用到自身
parentComponentId是Component的另一个实例。 - 如果解决了 #1 中的引用问题,我该如何执行类似于此的查询:
select a.*, b.* from COMPONENT a join COMPONENT b on a.id = b.parentComponentId group by a.id having sum(b.total) = a.total
【问题讨论】:
-
看看这里:stackoverflow.com/questions/17653567/…。似乎您应该将
Long属性替换为Component一个。
标签: grails grails-orm