using onDelete with Doctrine 2

纵饮孤独 提交于 2019-12-09 11:43:07

问题


I can't get the onDelete to work in Doctrine2 (with YAML Mapping).

I tried this relation in my Product class:

oneToOne:
    category:
      targetEntity: Category
      onDelete: CASCADE

But that doesn't work..

EDIT:

I've set the ON DELETE: CASCADE manually in the database

imported the YAML mapping with doctrine:mapping:import,

emptied the database

updated it from the schema with doctrine:schema:update and got no ON DELETE in the foreign key.. so looks like even Doctrine doesn't know how to do it lol..


回答1:


OK, got it! I had to use onDelete inside joinColumn:

oneToOne:
    category:
        targetEntity: Category
        joinColumn:
            onDelete: CASCADE



回答2:


This is the way to use onDelete in joinTable:

manyToMany:
    parameters:
        targetEntity: Fox\LandingBundle\Entity\Parameter
        cascade: ["persist","remove"]
        joinTable:
            name: subscriberBox_parameter
            joinColumns:
                subscriberBox_id:
                    referencedColumnName: id
            inverseJoinColumns:
                parameter_id:
                    referencedColumnName: id
                    onDelete: CASCADE


来源:https://stackoverflow.com/questions/8318480/using-ondelete-with-doctrine-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!