代码之家  ›  专栏  ›  技术社区  ›  Lars Andren

如何重写Grails GORM中关系的级联删除?

  •  3
  • Lars Andren  · 技术社区  · 14 年前

    在数据库中我有两个表 模板 报告 Template Report ;

    class Template {
    
    static hasMany = [reports: Report]
    
    ...
    }
    

    class Report {
    
    static belongsTo = [template: Template]
    
    ...
    }
    

    违约行为似乎是 模板 如果删除,则删除将被级联,以便 它也将被删除。 模板id -中的列 报告 -表be a 外键,但没用。

    有什么方法可以覆盖级联删除吗?

    1 回复  |  直到 14 年前
        1
  •  7
  •   Lars Andren    14 年前

    应在 Template 班级:

    static mapping = {
      reports cascade: 'none'
    }
    

    模板 没有问题,除了 Report 上课也是必要的:

    static constraints = {
      template(nullable: true)
    }
    
    推荐文章