I have the following areas in GORM.
class Topic {
static hasMany = [resources: Resource, subscriptions: Subscription]
}
class Resource {
static belongsTo = [resourceOf: Topic]
}
class Subscription {
static belongsTo = [subscriptionOf: Topic]
}
I could not find the syntax for running subqueries using the / named criteria subqueries. For example, how can I write below a query in GORM using criteria.
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;
This is a very simple thing, but I can not find the documentation for it.
Does anyone know how this can be done using namedQueries in GORM?
My version of grails is 2.4.4
source
share