api-platform / api-platform/core

Links require same ID type

Abierto
#5,269 5 comentarios 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
PHP
Estrellas
2.6k
Forks
980
Merge medio
2 d 4 h
PR fusionados (30 d)
49

Descripción

**API Platform version(s) affected**: 3.0.7

**Description**
`Link`s require the same property type when following the example here: https://api-platform.com/docs/core/subresources/#company-employees

If the `id` type is a `string` on `Company`, it will fail if the `id` is type `UUIDv4` for example on `Employee`. The issue is caused because the type is retrieved from the last identifier in the URL, and not for the particular identifier.

**How to reproduce**
See the link above.

**Possible Solution**
```
--- /dev/null
+++ ../src/Doctrine/Orm/State/LinksHandlerTrait.php
@@ -118,6 +118,9 @@
$queryBuilder->join("{$previousAlias}.{$link->getToProperty()}", $joinAlias);

foreach ($identifierProperties as $identifierProperty) {
+ $associationTargetClass = $doctrineClassMetadata->getAssociationMapping($link->getToProperty())['targetEntity'];
+ $doctrineClassMetadata = $manager->getClassMetadata($associationTargetClass);
+
$placeholder = $queryNameGenerator->generateParameterName($identifierProperty);
$queryBuilder->andWhere("$joinAlias.$identifierProperty = :$placeholder");
$queryBuilder->setParameter($placeholder, $this->getIdentifierValue($identifiers, $hasCompositeIdentifiers ? $identifierProperty : null), $doctrineClassMetadata->getTypeOfField($identifierProperty));

```
**Additional Context**
I didn't submit this as a PR as I'm not sure if there is more to the code that maybe we need to change, but this did solve our issue.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.