如何覆盖 Grails GORM 中关系的级联删除?
我在使用 Grails 的 GORM 部分时遇到一些问题。我正在使用 Grails 1.3.4 和 H2。
在数据库中,我有两个表模板和报告。在 GORM 级别,我有两个域类 Template
和 Report
;
class Template {
static hasMany = [reports: Report]
...
}
默认
class Report {
static belongsTo = [template: Template]
...
}
行为似乎是,当删除 Template
时,删除操作将被级联,以便它拥有的所有 Report
也将被删除。 在数据库级别,我尝试将 report 表中的 template_id 列设置为 ON DELETE SET NULL 外键,但这并没有不工作。
有没有办法覆盖级联删除?
I'm having some problems with the GORM part of Grails. I am using Grails 1.3.4, together with H2.
In the database I have two tables template and report. On the GORM-level I have the two Domain classes Template
and Report
;
class Template {
static hasMany = [reports: Report]
...
}
and
class Report {
static belongsTo = [template: Template]
...
}
Default behaviour seems to be that when a Template
is deleted, the deletion will be cascaded so that all Report
s that it has will be deleted as well.
On the database level I tried to make the template_id-column in the report-table be a ON DELETE SET NULL foreign key , but that didn't work.
Is there some way to override the cascade delete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应在
Template
类中添加以下内容:为了能够毫无问题地删除
Template
,向Report
类添加此内容也是必要的:The following should be added in the
Template
class:to be able to delete
Template
s without problems, this addition to theReport
class is also necessary: