Doctrine2删除问题

时间:2013-09-14 19:05:36

标签: php symfony doctrine-orm

从我之前的问题(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”] 但仍然没有

0 个答案:

没有答案