鉴于这些域类:
class Team {
hasMany = [players: Player, logsEntries: LogEntry]
}
class Player {
belongsTo = [team: Team]
def beforeDelete() {
team.addToLogEntries('player deleted')
}
}
class LogEntry {
belongsTo = [team: Team]
}
我在beforeDelete
中得到一个例外,说team
是null
。我还尝试用beforeDelete
包装LogEntry.withNewSession { ... }
的内容,但错误仍然存在。
任何想法,如果我想做的事情都可能吗?
编辑:当我考虑如何删除players
:
def team = Team.get(id)
playersToDelete.each {
team.removeFromPlayers(it)
it.delete()
}
所以我在beforeDelete
被调用之前打破了关系,因此team
是null
。但是,我确实尝试更改顺序(delete()
然后removeFromPlayers
,这没有帮助。我还尝试在all-delete-orphan
上为players
设置Team
这也没有帮助:(