Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using onDelete with Doctrine 2

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..

like image 322
tamir Avatar asked Nov 29 '11 22:11

tamir


2 Answers

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

oneToOne:
    category:
        targetEntity: Category
        joinColumn:
            onDelete: CASCADE
like image 173
tamir Avatar answered Oct 31 '22 17:10

tamir


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
like image 45
Serge Kvashnin Avatar answered Oct 31 '22 17:10

Serge Kvashnin