【问题标题】:Grails - remove from join table and delete the hasMany objectsGrails - 从连接表中删除并删除 hasMany 对象
【发布时间】:2015-06-30 15:35:30
【问题描述】:

我有以下域类:

class Shift {
    //etc
}

class Schedule{
    //etc
    static hasMany = [shifts:Shift]
    //etc
}

目前在删除控制器操作中,我先执行 schedule.shifts.c​​lear(),然后执行 schedule.delete()。这将删除调度记录本身和 ejoin 表中的关联,但班次对象仍然存在。如何同时删除这些?

【问题讨论】:

    标签: grails grails-orm has-many


    【解决方案1】:

    解决了这个问题:

    def shifts = schedules.shifts
    shifts*.delete()
    

    【讨论】:

      【解决方案2】:

      您必须提供back-ref 才能启用级联删除:

      class Shift {
        static belongsTo = [ schedule:Schedule ]
      }
      

      那么您应该可以使用schedule.delete() 来删除移位实例

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-03
        • 2020-04-17
        • 1970-01-01
        相关资源
        最近更新 更多