DoctrineExtensions
DoctrineExtensions copied to clipboard
[SoftDeleteable] Wrong commit order with cascade remove and hard delete
Assume we have the following
class A {
use SoftDeleteableEntity;
#[ORM\OneToMany(mappedBy: 'a', targetEntity: 'B', cascade: ['remove'], orphanRemoval: true)]
private $b = [];
}
class B {
use SoftDeleteableEntity;
#[ORM\ManyToOne(targetEntity: 'A', inversedBy: 'a')]
private A $a;
}
if you will try to remove entity A with
$a = new A();
$b = new B();
$a->addSomeHow($b);
$a->setDeletedAt(new DateTime());
$b->setDeletedAt(new DateTime());
$entityManager->remove($a);
$entityManager->flush();
you will get in postgres
Foreign key violation: 7 ERROR: update or delete on table "a" violates foreign key constraint "fk_37e6a6c613fecdf" on table "b"
this error occurs only when Gedmo\SoftDeleteable is used. If I remove Gedmo attributes from entities the deletion goes well. So I think this is not the problem of doctrine itself
did small investigation. seems to me softdeletable does not support cascade: remove... because there is no B entity for deletion in UoW in doctrine
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.