views:

45

answers:

1

In Grails, I like to have a many-to-many relation among entries of the same domain class Person. Relations will link to different persons the "leftPerson" and the "rightPerson" since the "Parent-child" and "Employer-Employee" relations will discriminate the position of each link.

That I would like to have is something like the following model:

class Person { String name

static hasMany = [relations:Relation] }

class Relation{ String type Person leftPerson Person rightPerson

static belongsTo = [person:Person] }

Any entry in Relations will be visible from both Persons.

I like to avoid having in Person two entries in'hasMany'and mappedBy if possible.

Is there any way to do it?

A: 

Take a look on many-to-many example of GORM many-to-many chapter.

class Person { 
    String name
    static hasMany = [relations:Relation]
}

 

class Relation {
    String type 
    static hasMany = [persons: Person]
    static belongsTo = Person
}
amra