using onDelete with Doctrine 2

tamir picture tamir · Nov 29, 2011 · Viewed 8.6k times · Source

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

Answer

tamir picture tamir · Nov 30, 2011

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

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