fix(custom-fields) : match by orderIndex to prevent value loss on rename

When a ModelType's custom field was renamed without sending the field ID,
the service would create a new CustomField instead of reusing the existing
one, orphaning all CustomFieldValues. Now matches by orderIndex as fallback
before name, preserving the link to existing values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-24 08:36:59 +01:00
parent 509c4d2247
commit 4468fd7cdf
3 changed files with 63 additions and 5 deletions

View File

@@ -382,6 +382,8 @@ abstract class AbstractApiTestCase extends ApiTestCase
string $value = 'test value',
?Machine $machine = null,
?Composant $composant = null,
?Piece $piece = null,
?Product $product = null,
): CustomFieldValue {
$cfv = new CustomFieldValue();
$cfv->setValue($value);
@@ -392,6 +394,12 @@ abstract class AbstractApiTestCase extends ApiTestCase
if (null !== $composant) {
$cfv->setComposant($composant);
}
if (null !== $piece) {
$cfv->setPiece($piece);
}
if (null !== $product) {
$cfv->setProduct($product);
}
$em = $this->getEntityManager();
$em->persist($cfv);