从我之前的问题(Symfony2 delete entities, cascade exception)
拥有此实体:
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"]
SelectedRiskAssesment:
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”] 但仍然没有