私は非常に単純な関係を持っており、通常はカスケード削除が機能するはずです。私の関係は次のようになります:
enum StatusName {
PENDING, SENDING, SENT
}
abstract class Notification {
StatusName status = StatusName.PENDING
Date dateCreated
Date scheduledDate
String text = ""
User recipient
boolean hasBeenSeen = false
static belongsTo = [
selectedChannel: SelectedChannel
]
static constraints = {
status blank: false,
inList:[StatusName.PENDING, StatusName.SENDING, StatusName.SENT]
scheduledDate nullable: true
text size: 0..1000
recipient nullable: true
}
def beforeInsert() {
if(!recipient) {
recipient = selectedChannel?.user
}
}
}
そしてここで他のクラス:
パッケージde.carmeq.carmob
class SelectedChannel {
static hasMany = [
notifications: Notification
]
static belongsTo = [
channel: Channel,
user: User,
notificationType: NotificationType
]
static constraints = {
channel blank: false,
user blank: false,
notificationType blank: false, unique: ['channel', 'user']
}
}
特定のユーザーの選択されたすべてのチャネルを削除したいので、次のようにします。
Collection<SelectedChannel> selectedChannels = SelectedChannel.findAllByUser(greedyUser)
selectedChannels*.delete()
ただし、これにより次のエラーが発生します。
Referential integrity constraint violation: "FK237A88EBC25A325D: PUBLIC.NOTIFICATION FOREIGN KEY(SELECTED_CHANNEL_ID) REFERENCES PUBLIC.SELECTED_CHANNEL(ID)"; SQL statement:
selected_channelから削除します。id=?およびversion=?[23503-164]
このようにすべての通知を削除しても:
Collection<Notification> notifications = Notification.findAllByRecipient(greedyUser)
notifications*.delete()
同じエラーが発生します...
ご挨拶