I have the following domains in GORM.
class Topic {
static hasMany = [resources: Resource, subscriptions: Subscription]
}
class Resource {
static belongsTo = [resourceOf: Topic]
}
class Subscription {
static belongsTo = [subscriptionOf: Topic]
}
I have been unable to find the syntax for running subqueries using criterias/named subqueries. For example how can I write the below query in GORM using criterias.
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 very basic thing but I have unable to find the documentation for the same.
Does anyone know how this can be done using namedQueries in GORM?
My grails version is 2.4.4