4

我在使用 Grails 的 GORM 部分时遇到了一些问题。我正在使用 Grails 1.3.4 和 H2。

在数据库中,我有两个表模板报告。在 GORM 级别上,我有两个 Domain 类TemplateReport;

class Template {

static hasMany = [reports: Report]

...
}

class Report {

static belongsTo = [template: Template]

...
}

默认行为似乎是当 aTemplate被删除时,删除将被级联,以便Report它所拥有的所有 s 也将被删除。在数据库级别上,我尝试使report -table中的template_id -column成为ON DELETE SET NULL foreign key ,但这不起作用。

有没有办法覆盖级联删除?

4

1 回答 1

7

应在Template类中添加以下内容:

static mapping = {
  reports cascade: 'none'
}

为了能够Template毫无问题地删除 s,这个Report类的添加也是必要的:

static constraints = {
  template(nullable: true)
}
于 2010-11-09T07:51:11.577 回答