I have
class A {
String title
static hasMany = [details: Detail]
}
class Detail {
enum Type { ONE, TWO }
String name
Type开发者_高级运维 type
static belongsTo = [a: A]
}
How can I get list of all Details type ONE for specified object a?
I tried
def all_one = A.get(params.id).details.findByType(Detail.Type.ONE)
but it does not work.
I think you should be able to use the Groovy collections API to do:
A.get(params.id).details.findAll { it.type == Detail.Type.ONE }
Or, you might be able to go from the Detail back up with:
Detail.findByAAndType( A.get(params.id), Detail.Type.ONE )
Though I haven't tested that out...
精彩评论