I just did something similar; I think the mapping would be:
class User {
String name
static hasMany=[users:User]
static belongsTo = [user: User]
static constraints = {
user nullable: true
}
}
'user' is nullable for the BigBoss case.
Burt
On Thursday 15 May 2008 10:50:30 am syg6 wrote:
> 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
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email