ObjectMapper wrong association with child entity
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 領域
- api, backend, backend-api-design
調査の方向性
提供されている Product と Category の entity/DTO 定義および Symfony ObjectMapper の設定から始め、その後、Category とのリレーションで報告されている GET のマッピングエラーを再現します。Product DTO の category が、報告されている型エラーなしに Category entity から正しくマッピングされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- PHP
- スター
- 2.6k
- フォーク
- 987
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 76
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/core のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
api-platform/core#8665 ·
メンテナーはふだん 1 日以内に返信
-
Doctrine\Orm\OrderExtension fails on SortDirection対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
api-platform/core#8660 ·
メンテナーはふだん 1 日以内に返信
-
DeserializeProvider calls PartialDenormalizationException::getErrors(), deprecated in Symfony 8.1対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
api-platform/core#8650 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
api-platform/core#8649 ·
メンテナーはふだん 1 日以内に返信
-
`OrderExtension` and `OrderFilter` pass string sort directions, deprecated since `doctrine/orm` 3.7オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
api-platform/core#8648 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
api-platform/core の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
backdrop-contrib/commerce#60 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
-
needs-triage Platform(Default)
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
Feature-Request
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
RSS-Bridge/rss-bridge#5123 ·
メンテナーはふだん 1 日以内に返信
-
[Store] RstLoader detects headings inside indented code blocks対応中かも @lazerg が今日担当しました。 オープンBug Status: Needs Review Store
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信