开发者

How can I get all details objects with specified condition?

开发者 https://www.devze.com 2023-03-06 11:10 出处:网络
I have class A { String title static hasMany = [details: Detail] } class Detail { enum Type { ONE, TWO } String name

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...

0

精彩评论

暂无评论...
验证码 换一张
取 消