【发布时间】:2015-04-30 03:56:44
【问题描述】:
我在 GORM 中有以下域。
class Topic {
static hasMany = [resources: Resource, subscriptions: Subscription]
}
class Resource {
static belongsTo = [resourceOf: Topic]
}
class Subscription {
static belongsTo = [subscriptionOf: Topic]
}
我一直找不到使用条件/命名子查询运行子查询的语法。例如,如何使用条件在 GORM 中编写以下查询。
select topic.id,
(select count(*) from Resource where resourceOf.id = topic.id) as numRes,
(select count(*) from Subscription where subscriptionOf.id = topic.id) as numSubs
from topic
where topic.id in (<My topic ids>)
group by topic.id;
这是非常基本的事情,但我找不到相同的文档。
有谁知道如何在 GORM 中使用 namedQueries 来做到这一点?
我的 grails 版本是 2.4.4
【问题讨论】:
标签: hibernate grails subquery grails-orm