diff --git a/src/Controller/MachineStructureController.php b/src/Controller/MachineStructureController.php index 10f753d..7331a55 100644 --- a/src/Controller/MachineStructureController.php +++ b/src/Controller/MachineStructureController.php @@ -337,6 +337,7 @@ class MachineStructureController extends AbstractController $newValue->setMachineComponentLink($newLink); $newValue->setComposant($newLink->getComposant()); $this->entityManager->persist($newValue); + $newLink->getContextFieldValues()->add($newValue); } } @@ -352,6 +353,7 @@ class MachineStructureController extends AbstractController $newValue->setMachinePieceLink($newLink); $newValue->setPiece($newLink->getPiece()); $this->entityManager->persist($newValue); + $newLink->getContextFieldValues()->add($newValue); } } } diff --git a/tests/AbstractApiTestCase.php b/tests/AbstractApiTestCase.php index 8ad92b5..a0d8012 100644 --- a/tests/AbstractApiTestCase.php +++ b/tests/AbstractApiTestCase.php @@ -7,10 +7,10 @@ namespace App\Tests; use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; use ApiPlatform\Symfony\Bundle\Test\Client; use App\Entity\Composant; +use App\Entity\ComposantConstructeurLink; use App\Entity\ComposantPieceSlot; use App\Entity\ComposantProductSlot; use App\Entity\ComposantSubcomponentSlot; -use App\Entity\ComposantConstructeurLink; use App\Entity\Constructeur; use App\Entity\CustomField; use App\Entity\CustomFieldValue; @@ -467,6 +467,14 @@ abstract class AbstractApiTestCase extends ApiTestCase $em->persist($cfv); $em->flush(); + // Keep inverse-side collections in sync so identity-mapped entities reflect the new CFV. + if (null !== $machineComponentLink && !$machineComponentLink->getContextFieldValues()->contains($cfv)) { + $machineComponentLink->getContextFieldValues()->add($cfv); + } + if (null !== $machinePieceLink && !$machinePieceLink->getContextFieldValues()->contains($cfv)) { + $machinePieceLink->getContextFieldValues()->add($cfv); + } + return $cfv; }