Olá pesoal, gostaria da opinião de vocês sobre um comportamento do Grails:
tenho as seguintes domains:
Person
class Person extends AbstractPerson implements Serializable {
String gender
String lastName
Language language
Location location
static hasMany = [socialAppAccount: SocialAppAccount]
}
Notification
class Notification implements Serializable {
String message
Date sentDate
Person sender
static hasMany = [recipients: Person]
}
PersonNotifications
class PersonNotifications implements Serializable {
Person person
static hasMany = [received: Notification, read: Notification]
}
No caso da PersonNotification foi gerada a tabela "person_notifications" que possui apenas id, version e person_id, e a tabela "person_notifications_notification" para os relacionamentos com Notification. Ao meu ver, a tabela "person_notifications_notification" deveria ter uma FK para PersonNotiication e 2 FKs para Notification (uma para "read" e outra para "received"). Entretanto, o que foi gerado foram 2 FKs para PersonNotification ("person_notification_read_id" e "person_notification_received_id") e uma FK para Notification (chamada "person_notification_id").
Tentei contornar o problema usando "static mapping" na domain PersonNotification, conforme abaixo:
class PersonNotifications implements Serializable {
Person person
static hasMany = [received: Notification, read: Notification]
static mapping = {
receiveds joinTable: [name: 'person_notifications_notification', column: 'received_id']
reads joinTable: [name: 'person_notifications_notification', column: 'read_id']
}
}
Desta forma foram geradas 4 FKs, 2 referenciando PersonNotification("person_notification_read_id" e "person_notification_received_id") e 2 referenciando Notification("received_id" e "read_id").
Como posso fazer para realizar este mapeamento corretamente?