Somehow UnitOfWork delete first parent entity but not children with cascade remove, thus throwing ForeignKeyConstraintViolationException #5264

Open
opened 2026-01-22 15:02:57 +01:00 by admin · 0 comments
Owner

Originally created by @idchlife on GitHub (Sep 20, 2016).

This is the place where UnitOfWork continues (in loop) with child entity with relation OneToMany and deletes parent before child.

image

I have this in User entity:

image

and this in Gallery entity:

image

Apparently, Gallery does not have className as User and it's deletion is not executed before user.
But, in UnitOfWork::$entityDeletions gallery comes first and user second. Because of foreign key gallery should be deleted first, then user.

Is this a bug or have I done something wrong?

More info on entityDeletions property:

image

and part where it checking whether className is equal with entity className

image

Originally created by @idchlife on GitHub (Sep 20, 2016). This is the place where UnitOfWork continues (in loop) with child entity with relation OneToMany and deletes parent before child. ![image](https://cloud.githubusercontent.com/assets/4563032/18664842/0dbf211e-7f2d-11e6-8bfc-e3bff56bfdba.png) I have this in User entity: ![image](https://cloud.githubusercontent.com/assets/4563032/18664857/1e266e86-7f2d-11e6-9107-5f5b9e121dec.png) and this in Gallery entity: ![image](https://cloud.githubusercontent.com/assets/4563032/18664880/39e939f0-7f2d-11e6-9f19-9ea9399ec13b.png) Apparently, Gallery does not have className as User and it's deletion is not executed before user. But, in UnitOfWork::$entityDeletions gallery comes first and user second. Because of foreign key gallery should be deleted first, then user. Is this a bug or have I done something wrong? More info on entityDeletions property: ![image](https://cloud.githubusercontent.com/assets/4563032/18665340/77a2c6a6-7f2f-11e6-95aa-67471abc3ff7.png) and part where it checking whether className is equal with entity className ![image](https://cloud.githubusercontent.com/assets/4563032/18665395/c6479962-7f2f-11e6-9be2-3db76d80a21c.png)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5264