I have entity "A" with the following property:
manyToOne:
b:
targetEntity: App\Entity\B
joinColumn:
name: b_id
referencedColumnName: id
How can I update the value of entity "A", when delete the entity "B", instantly?
e.g.:
$a = new A();
$b = $bRepository->find(1);
$a->setB($b);
$em->persist($a);
$em->flush();
// table a: table b:
// +----+------+ +----+
// | id | b_id | | id |
// +----+------+ +----+
// | 1 | 1 | | 1 |
// +----+------+ +----+
$em->remove($b);
$em->flush();
// table a: table b:
// +----+------+ +----+
// | id | b_id | | id |
// +----+------+ +----+
// | 1 | NULL |
// +----+------+
I can do it with the MySQL trigger, but maybe there exists some configuration for table or doctrine to do it w\o triggers?
The main problem is that I can't modify the entity "B" or update entity "A" with $a->setB(null); $em->persist($a);
on "B" removing, because it in shared bundle and using in several projects