I am working with Doctrine 2.4.2, Symfony 2.4 and SQLite 3.8.3.
I have two entities defined:
Category:
type: entity
id:
id:
type: integer
id: true
generator:
strategy: AUTO
oneToMany:
ministries:
targetEntity: Ministry
cascade: [persist]
mappedBy: category
And
Ministry:
type: entity
id:
id:
type: integer
id: true
generator:
strategy: AUTO
manyToOne:
category:
targetEntity: Category
inversedBy: ministries
joinColumn:
name: category_id
nullable: false
onDelete: CASCADE
But when I delete a category, the ministry entities do not get deleted, although the constraint should cascade. What am I missing?
Do I have to configure anything to get that working?
You may need to make sure that PRAGMA foreign_keys = ON
is set before deleting.
Note that this is a connection setting, not a database setting.
Addition:
With Symfony's event subscriber it is possible to execute this command in the preFlush event of Doctrine, before any writing queries are executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With