How to count ocurrences in 1 to many relationship in gorm - grails
Posted
by xain
on Stack Overflow
See other posts from Stack Overflow
or by xain
Published on 2010-04-24T19:43:57Z
Indexed on
2010/04/25
3:33 UTC
Read the original article
Hit count: 276
Hi, I have 2 domain classes
class A {
....
static hasMany = [bs:B]
}
class B {
int code
....
}
How can I list the number of ocurrences of all codes in B in all the A table?
Something like
b.each { thisb ->
int ocurrences = A.bs.findAll{it == thisb}.size()
...
}
Thanks
© Stack Overflow or respective owner