fix(machine-clone) : preserve context field values when cloning a machine
All checks were successful
Auto Tag Develop / tag (push) Successful in 35s
All checks were successful
Auto Tag Develop / tag (push) Successful in 35s
Context CustomFieldValues attached to component/piece links were silently dropped from the clone response (and from any subsequent read in the same request) because the controller persisted the new CFVs without adding them to the inverse-side collection of the new link. Doctrine does not auto-sync inverse OneToMany associations, so getContextFieldValues() returned an empty collection on the freshly persisted link. Also synchronise the inverse collection in the test factory so identity-mapped entities reflect newly-created CFVs when reused by request handlers within the same test. Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user