1

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?

Charles
  • 50,943
  • 13
  • 104
  • 142
Daniel T.
  • 37,212
  • 36
  • 139
  • 206
  • `hasMany` and `belongsTo` should be static. – Burt Beckwith Mar 13 '14 at 01:07
  • Thanks, I updated my question. It's just an example, so I typed it by hand. – Daniel T. Mar 13 '14 at 01:14
  • You can achieve what you want doing something similar to [this](http://stackoverflow.com/a/16472407/2051952) adding a flag in Person to determine if Person is the primary contact instead of adding it to Family. Mark the comments in the domain class. – dmahapatro Mar 13 '14 at 01:27

0 Answers0