However, adding the relationship to User breaks the hasMany on the contact. When I tried to retrieve the hasMany relationship for 'usersWhoOwnContact', instead of looking in the join table, it looks for the '_idx' column in the User table. I'm not sure why it is confusing the 2 different relationships here. I've tried various uses of 'hasOne' and 'mappedBy'. It either erroneously thinks my hasMany is bi-directional, or fails during the lookup of the hasMany relationship. Has anyone else encountered this and the proper scenario for modeling this?
I want the hasMany to use it's own join table. I want the bi-directional single relationship to use the columns in each table, or even better, just the column for the ID saved for it in the contacts table. It seems I can't have both. If I remove all relationships to Contact from User, the relationships on Contact seem to work fine.
1. yes - a user can be assigned to a contact (or none at all)
2. yes - but basically for admin users. I.e. a user may 'own' 1 or more contacts
3. no - a user can be their own contact. This is giving me the linkage of a user->contact.
The problem is I am having 2 different purpose linkages for a user to a contact. One for a user to 'own' a group of contacts, the other is to associate a user to a contact. It seems grails is confused by this, if the user <-> contact is bidirectional, and the 'owning' contact relationship is unidirectional.
As far as I can tell Grails doesn't allow this: I ended up having to move one of the relationships to an intermediate object and link it up there - not as clean, but I suppose this is one of those areas Grails just can't handle.
----- Original Message -----
From: "Paul Fernley" <[hidden email]>
To: [hidden email] Sent: Tuesday, November 1, 2011 7:22:48 AM GMT -06:00 US/Canada Central
Subject: [grails-user] Re: Is it possible to do this in grails?
Am I correct in thinking that the 'real world' situation that you are trying
to model is:
1. A user is assigned a single contact.
2. A user may be assigned as the contact for zero or more other users.
3. A user cannot be their own contact.
BTW, it seems like you will probably need to allow for a user having no
contact, otherwise you would never be able to enter the very first user.