How do I properly map a domain that has a one-to-many as well as a many-to-one to another domain?

52 Views Asked by At

Let's say I have the following domain objects:

class Family {
    Person primaryContact
    static hasMany = [ members: Person ]
}

class Person {
    static belongsTo = [ family: Family ]
}

In other words, a Family can have multiple members, but only one Person, who is also in the members, can be the primaryContact. Family has a bidirectional one-to-many relationship with Person, but it also has a unidirectional many-to-one relationship with Person as well.

My question is, have I mapped this properly? According to the database tables, the correct columns are created, but the build-testdata plugin can't build an instance of Family because one of the Person instances is transient and wasn't saved.

Can someone please help?

0

There are 0 best solutions below