0

我有一个名为Step2的实体(有多个 selectedriskassesments 实体,这是一个带有额外字段的 RiskAssestment 实体):

......................
    manyToMany:
       selectedriskassesments:
         targetEntity: **SelectedRiskAssesment**
         joinTable:
           name: step2_selected_risk_assesments
           joinColumns:
             step2_id:
               referencedColumnName: id
           inverseJoinColumns:
             selected_risk_id:
               referencedColumnName: id 
         cascade: ["persist","remove"]
..............................

SelectedRiskAssesment实体具有:

 manyToOne:
        risk_assesment:
            targetEntity: RiskAssestment
            inversedBy: selectedriskassesment
            joinColumn:
                name: risk_assesment
                referencedColumnName: id
            orphanRemoval: true

这是调查的一部分,我想删除 Step2实体及其选定的风险评估,但我得到:

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`phsafety`.`step2_selected_risk_assesments`, CONSTRAINT `FK_FAFC9298EA71C84F` FOREIGN KEY (`selected_risk_id`) REFERENCES `selectedriskassesment` (`id`))

我曾尝试使用orphanRemoval: true解除与RiskAssestment实体的绑定...任何帮助都会很棒

4

1 回答 1

0

我不得不更改 Step2 实体:

  manyToMany:
       selectedriskassesments:
         targetEntity: **SelectedRiskAssesment**
         joinTable:
           name: step2_selected_risk_assesments
           joinColumns:
             step2_id:
               referencedColumnName: id
           inverseJoinColumns:
             selected_risk_id:
               referencedColumnName: id 
               onDelete: CASCADE
         cascade: ["persist","remove"]

不得不添加onDelete: CASCADE,灵感来自

  • 埃尔努尔·阿卜杜拉希莫夫
于 2013-09-14T17:18:06.297 回答