Self-referencing one-to-many: how to get the owner?
I have this class:
class User
{
String name
static hasMany=[users:User]
}
A uni-directional one-to-many where each User can contain a Collection of Users, and each User belongs to exactly one User. This might seem a little complicated but it's what I need. The reason is I have different types of Users: (these aren't the real names ...)
User type I, BigBoss - has 1-3 Managers, belongs to no one.
User type II, Manager - has 1-5 Schmucks, belongs to a BigBoss.
User type III, Schmuck - has nobody, belongs to a Manager.
The problem is, I'd like to know who my 'owner' is. In other words, if I am a Schmuck, who is my Manager, and if I am a Manager, who is my BigBoss?
I tried making the following change to my class, to make it bi-directional:
class User
{
String name
User user
static hasMany=[users:User]
static belongsTo = User
}
But it doesn't work. Now my Collections aren't being populated.
Can someone help me out?
Thanks,
Bob