I am trying to create 2 domain classes User
and MailBox
There will be 2 Mailbox
for each User
, one is sent
, another is inbox
.
I've tried multiple ways of solving this:
1 - (fails with a mapping exception)
Mailbox {
}
User {
static hasOne=[inbox:Mailbox, sent:Mailbox]
}
2 - (perfectly fine until i tries to use it, then the value of sent
becomes null
at all times)
Mailbox {
static belongsTo = [user: User]
}
User {
Mailbox inbox
Mailbox sent
}
3 - (when I tried to create a new User by: new User(inbox: new Mailbox(), sent: new Mailbox()).save()
it fails)
Mailbox {
static belongsTo = [user: User]
}
User {
static mappedBy = [inbox: 'id', sent: 'id']
Mailbox inbox
Mailbox sent
}
What is the proper way of creating this relationship?