DoctrineExtensions icon indicating copy to clipboard operation
DoctrineExtensions copied to clipboard

[SoftDeleteable] Wrong commit order with cascade remove and hard delete

Open jokaorgua opened this issue 2 years ago • 1 comments

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

jokaorgua avatar Apr 26 '22 07:04 jokaorgua

did small investigation. seems to me softdeletable does not support cascade: remove... because there is no B entity for deletion in UoW in doctrine

jokaorgua avatar Apr 26 '22 07:04 jokaorgua

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.

github-actions[bot] avatar Oct 23 '22 09:10 github-actions[bot]