In Grails, How can I create a domain model to link two of another model?

Posted by gerges on Stack Overflow See other posts from Stack Overflow or by gerges
Published on 2010-04-22T03:58:14Z Indexed on 2010/04/22 4:03 UTC
Read the original article Hit count: 212

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about grails

Related posts about gorm