从我以前的问题(Symfony2 删除实体,级联异常)
拥有这个实体:
Service\SafetyBundle\Entity\Step2:
type: entity
table: step2
repositoryClass: Service\SafetyBundle\Entity\Step2Repository
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"]
选定风险评估:
Service\SafetyBundle\Entity\SelectedRiskAssesment:
type: entity
table: selectedriskassesment
repositoryClass: Service\SafetyBundle\Entity\SelectedRiskAssesmentRepository
manyToOne:
risk_assesment:
targetEntity: RiskAssestment
inversedBy: selectedriskassesment
joinColumn:
name: risk_assesment
referencedColumnName: id
cascade: ["detach"]
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
answer:
type: boolean
lifecycleCallbacks: { }
在删除第 2 步时,它会删除所有selectedriskassesments
我不想要的 RiskAssestment 实体。
如果我删除onDelete: CASCADE它会产生一个异常,试图把cascade: ["detach"]但仍然没有