In Grails, How can I create a domain model to link two of another model?
- by gerges
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?