Lar*_*ren 3 grails h2 foreign-key-relationship relational-database grails-orm
我在Grails的GORM部分遇到了一些问题.我正在使用Grails 1.3.4和H2.
在数据库中,我有两个表模板和报告.在GORM级我有两个域类Template和Report;
class Template {
static hasMany = [reports: Report]
...
}
和
class Report {
static belongsTo = [template: Template]
...
}
默认行为似乎是当Template删除a时,删除将被级联,以便Report它所拥有的所有内容也将被删除.在数据库级别,我试图使报表中的template_id -column 为ON DELETE SET NULL外键,但这不起作用.
有没有办法覆盖级联删除?
应在Template课程中添加以下内容:
static mapping = {
  reports cascade: 'none'
}
为了能够Template毫无问题地删除s,这个Report类的添加也是必要的:
static constraints = {
  template(nullable: true)
}