我读到 am:m 关系通常意味着还不需要第三类。所以我有 m:m on User
and Project
,我创建了第三个域类,ProjectMembership
这三个域如下(为了便于说明而最小化):
用户
class User {
String name
static hasMany = [projectMemberships : ProjectMembership]
}
项目成员
class ProjectMembership {
static constraints = {
}
static belongsTo = [user:User, project:Project]
}
项目:
class Project {
String name
static hasMany = [projectMemberships : ProjectMembership]
static constraints = {
}
}
如果我有用户的 ID,如何获取Project
分配给他们的对象列表?