代码
class Member{
string name
}
class Group{
string name
static hasMany = [member: Member]
}
// CONTROLLER
def member = Member.get(1) // I get member object as expected
def group = Group.findByMember(member) //ERROR
问题
找不到这样的组......(因为组和成员是一对多的关系)
还有其他简单方法吗?
解决方案在这里:
http://adhockery.blogspot.com/2009/06/querying-by-association-redux.html
答案 0 :(得分:0)
解决方案在这里:
def group = Group.withCriteria {
createAlias("member", "m")
eq("m.id", 1)
}
<强>来源
http://adhockery.blogspot.com/2009/06/querying-by-association-redux.html