0

I have domain like this:

class Team {
 hasOne [leader: Person]
 hasMany [member: Person]
}

class Person {
 belongsTo [team: Team]
}

But when the tables are generated, there is not a column like leader_id in the team table. And thus the leader relation is not persisted.

How should I fix it?

Shaoxuan
  • 33
  • 4

2 Answers2

2

I figured that, what I need is

class Team {
 belongsTo [leader: Person]
 hasMany [member: Person]
}

class Person {
 belongsTo [team: Team]
}

so that the Team table can have the desired "leader" reference back to Person.

Stéphane Bruckert
  • 19,984
  • 11
  • 86
  • 121
Shaoxuan
  • 33
  • 4
1

Per the documentation:

Use a hasOne association to store the foreign key reference in child table instead of the parent in a bidirectional one-to-one.

You're child table here is Person and your parent is Team. Grails is working as expected.

Gregg
  • 33,473
  • 15
  • 101
  • 201
  • 6
    Right, so the OP should keep the `hasMany` to member but should change the `leader` to be just `Person leader` – Ted Naleid Jul 25 '12 at 13:37