views:

92

answers:

1

Hey all,

I'm currently trying to create a Friendship domain object to link two User objects (with a bit of additional data: createDate, confirmedStatus). My domain model looks as follows

class Friendship {

User userOne
User userTwo
Boolean confirmed
Date createDate
Date lastModifiedDate

static belongsTo = [userOne:User , userTwo:User]

static constraints = {
userOne()
userTwo()
confirmed()
createDate()
lastModifiedDate()
}
}

I've also added the following entries to the user class

static hasMany = [ friendships:Friendship ]
static mappedBy = [ friendships:'userOne' , friendships:'userTwo' ]

When I do this, the result is a new friendship created (and viewable through the controller) with both users listed in their respective places. When I view the details of userOne, I see the friedship listed. When I view the details of userTwo, no friendship is listed. This is not the behavior I expected. What am I doing incorrectly? Why can't I see the friendship listed under both users?

+1  A: 

You've declared the userOne and userTwo properties twice in the Friendship class. Once here:

static belongsTo = [userOne:User , userTwo:User]

And again here:

User userOne
User userTwo

Change your Friendship class to this

class Friendship {

  Boolean confirmed
  Date createDate
  Date lastModifiedDate

  static belongsTo = [userOne:User , userTwo:User]

  static constraints = {
    userOne()
    userTwo()
    confirmed()
    createDate()
    lastModifiedDate()
  }
}
Don
Didn't seem to make a difference, the friendship is still only seen as a property of one of the friends.
gerges