Search code examples
grailsgrails-orm

Uni-directional one-to-many in GORM


This might be really simple.

I have two domain classes - Member and GroupOfMembers.

class Member
{
    String memberName
}

class GroupOfMembers
{
    String groupName

    static hasMany = [members : Member]
}

As seen in above code, a Member can exist without a group or can be associated with one or more groups.

I am trying to figure out GORM query where I can list all groups to which a given member is associated with. The schema generated in this case has a join table for the two entities.

Thanks


Solution

  • If you haven't already figured this out try this for a particular member:

    def groupList = GroupOfMembers.createCriteria().list {
        members {
            eq('id', member.id)
        }
    }