我可以从beforeDelete()事件中访问belongsTo属性吗?

时间:2013-12-06 13:20:19

标签: grails gorm

鉴于这些域类:

class Team {
  hasMany = [players: Player, logsEntries: LogEntry]
}

class Player {
  belongsTo = [team: Team]
  def beforeDelete() {
    team.addToLogEntries('player deleted')
  }
}

class LogEntry {
  belongsTo = [team: Team]
}

我在beforeDelete中得到一个例外,说teamnull。我还尝试用beforeDelete包装LogEntry.withNewSession { ... }的内容,但错误仍然存​​在。

任何想法,如果我想做的事情都可能吗?


编辑:当我考虑如何删除players

时,这有点意义
def team = Team.get(id)
playersToDelete.each {
  team.removeFromPlayers(it)
  it.delete()
}

所以我在beforeDelete被调用之前打破了关系,因此teamnull。但是,我确实尝试更改顺序(delete()然后removeFromPlayers,这没有帮助。我还尝试在all-delete-orphan上为players设置Team这也没有帮助:(

0 个答案:

没有答案