Bug Report
| Q |
A |
| BC Break |
no |
| Version |
2.14.0 |
Summary
The order in which the UoW wants to delete children is somehow missing a dependency when there is an association to the same class even if you specified cascade: ['remove'].
Given you have
- Parent -> has an association to children with
cascade: ['remove']
- Child 1
- Child 2 -> has an association to Child 1 with
cascade: ['remove'].
Now you delete the parent.
Doctrine tries to remove Child 1 first instead of Child 2 causing a foreign constraint violation:
Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (test.child_entities, CONSTRAINT FK_DAEB194156A273CC FOREIGN KEY (origin_id) REFERENCES child_entities (id))
How to reproduce
I've created a test setup because I'm not familiar with the internals of ORM at all. So here we go:
- Clone https://github.com/Toflar/doctrine-orm-bug-reproducer
- Run
composer install
- Adjust dummy mysql connection example in
bootstrap.php.
- Run
bin/doctrine orm:schema-tool:drop --force && bin/doctrine orm:schema-tool:create
- Run
php test.php.
Expected behavior
It should not throw an exception. Doctrine should remove Child 2 first.
Bug Report
Summary
The order in which the UoW wants to delete children is somehow missing a dependency when there is an association to the same class even if you specified
cascade: ['remove'].Given you have
cascade: ['remove']cascade: ['remove'].Now you delete the parent.
Doctrine tries to remove Child 1 first instead of Child 2 causing a foreign constraint violation:
How to reproduce
I've created a test setup because I'm not familiar with the internals of ORM at all. So here we go:
composer installbootstrap.php.bin/doctrine orm:schema-tool:drop --force && bin/doctrine orm:schema-tool:createphp test.php.Expected behavior
It should not throw an exception. Doctrine should remove Child 2 first.