ObjectMapper wrong association with child entity
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Área
- api, backend, backend-api-design
Línea de trabajo
Comienza con las definiciones proporcionadas de entidad/DTO de Product y Category y la configuración de Symfony ObjectMapper; después, reproduce el error de mapeo GET informado para la relación con Category. Se considera terminado cuando la category del Product DTO se mapea correctamente desde la entidad Category sin el error de tipo informado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
API Platform version(s) affected: 4.2.14
Description
Hi !
When using ObjectMapper, child DTO management does not seem to work on a GET / GET Collection method.
When I have a Parent A entity that contains a child Aa and I have a DTO corresponding to these two entities, DtoA and DtoAa, then in my DtoA I am unable to map the child Dto.
Or perhaps I am missing something in my configuration or in my understanding of how to use ObjectMapper with ApiPlatform.
Maybe it's more related to ObjectMapper than ApiPlatform ?
How to reproduce
With this example, I get a mapping error on the category relationship. It seems that ObjectMapper is unable to connect to my resource.
Expected argument of type "?App\Api\ApiResource\Category", "App\Entity\Category" given at property path "category".
Entity Product :
declare(strict_types=1);
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Gedmo\Mapping\Annotation\Translatable;
use Symfony\Component\Validator\Constraints\NotBlank;
#[Entity]
class Product
{
#[Id]
#[GeneratedValue]
#[Column(type: Types::INTEGER)]
private ?int $id = null;
#[ManyToOne(targetEntity: Category::class)]
#[JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Category $category = null;
#[Column(type: Types::STRING)]
private string $name;
public function getId(): ?int
{
return $this->id;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): void
{
$this->category = $category;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
}
Entity Category :
<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
#[Entity]
class Category
{
#[Id]
#[GeneratedValue]
#[Column(type: Types::INTEGER)]
private ?int $id = null;
#[Column(name: 'label', type: Types::STRING, nullable: false)]
private ?string $label = null;
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(?string $label): void
{
$this->label = $label;
}
}
DTO Product :
declare(strict_types=1);
namespace App\Api\ApiResource;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\Entity\Product as ProductEntity;
use Symfony\Component\ObjectMapper\Attribute\Map;
#[ApiResource(
operations: [
new Get(
uriTemplate: '/products/{id}',
),
],
stateOptions: new Options(entityClass: ProductEntity::class)
)]
#[Map(source: ProductEntity::class)]
class Product
{
public int $id;
public string $name;
public ?Category $category = null;
}
DTO Category
<?php
declare(strict_types=1);
namespace App\Api\ApiResource;
use App\Entity\Category as CategoryEntity;
use Symfony\Component\ObjectMapper\Attribute\Map;
#[Map(source: CategoryEntity::class)]
class Category
{
public int $id;
public string $label;
}
Thank you for your help.
- Lenguaje dominante
- PHP
- Estrellas
- 2.6k
- Forks
- 987
- Merge medio
- 1 d 7 h
- PR fusionados (30 d)
- 84
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de api-platform/core
-
Doctrine\Orm\OrderExtension fails on SortDirectionPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
api-platform/core#8660 ·
Los mantenedores suelen responder en 1 día
-
DeserializeProvider calls PartialDenormalizationException::getErrors(), deprecated in Symfony 8.1Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
api-platform/core#8650 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
api-platform/core#8649 ·
Los mantenedores suelen responder en 1 día
-
`OrderExtension` and `OrderFilter` pass string sort directions, deprecated since `doctrine/orm` 3.7Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
api-platform/core#8648 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
api-platform/core#8647 ·
Los mantenedores suelen responder en 1 día
Todos los issues de api-platform/core
Issues similares
-
sync-en
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
sync-en
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 4 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Refund Analytics Tool — “Check” Button Fails to Render in WooCommerce 11.2.1Posiblemente ocupada @MinhazI la tomó hoy. AbiertoBug Reports/Analytics type: community contribution
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
woocommerce/woocommerce#69689 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
Los mantenedores suelen responder en 2 días