Using onDelete with Doctrine 2

I cannot get onDelete to work in Doctrine2 (using YAML Mapping).

I tried this relation in the Product class:

 oneToOne: category: targetEntity: Category onDelete: CASCADE 

But that does not work.

EDIT:

I installed ON DELETE: CASCADE manually in the database

imported YAML mapping with doctrine:mapping:import ,

empty database

updated it from the schema using doctrine:schema:update and did not get ON DELETE in the foreign key .. so even Doctrine does not know how to do it lol ..

+6
source share
2 answers

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

 oneToOne: category: targetEntity: Category joinColumn: onDelete: CASCADE 
+19
source

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 
+5
source

Source: https://habr.com/ru/post/902708/


All Articles