[Object Mapper] IriFilter / IriConverterParameterProvider fails to find items when filtering mapped resources
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
调研方向
Start by reading Doctrine ORM's IriFilter and IriConverterParameterProvider, then trace how the bar query parameter is handled for the mapped FooResource relation relation.bar. The report says filtering should match the underlying entity relation for /v2/foos?bar=/v2/bars/2; verify whether the mapped resource value causes the mismatch and identify the relevant test coverage.
由索引模型根据 Issue 内容生成。
描述
Environment
- API Platform version:
v5.0.5 - Symfony version:
8.1.*(symfony/object-mapper) - PHP version:
8.5 - Doctrine ORM:
^3.6.8
Description
Hey everyone!
I've been testing API Platform's new Object Mapper feature (Symfony\Component\ObjectMapper\Attribute\Map) with custom DTO resources acting as Entity DTOs, and it's honestly amazing. Everything works super smoothly—except when trying to filter a collection using an IriFilter combined with an IriConverterParameterProvider on a mapped relation (especially with nested property paths).
When calling an endpoint with an IRI filter like ?bar=/v2/bars/2, Doctrine successfully finds the target resource, but the filter ends up evaluating to false or failing to match because the IriFilter receives the already-mapped resource instead of resolving it against the underlying entity relation.
In the example below, when calling /v2/bars/2
the $value is an instance of BarResource.
Code Snippets
1. Collection Resource (FooResource)
namespace App\ApiResource\V2\Foo;
use ApiPlatform\Doctrine\Orm\Filter\IriFilter;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\QueryParameter;
use ApiPlatform\State\ParameterProvider\IriConverterParameterProvider;
use App\ApiResource\V2\Bar\BarResource;
use App\Entity\FooEntity;
use Symfony\Component\ObjectMapper\Attribute\Map;
#[ApiResource(
uriTemplate: '/v2/foos',
operations: [
new GetCollection(
parameters: [
'bar' => new QueryParameter(
provider: IriConverterParameterProvider::class,
filter: new IriFilter(),
property: 'relation.bar',
)
],
itemUriTemplate: FooResource::uriTemplate,
),
],
stateOptions: new Options(entityClass: FooEntity::class)
)]
#[Map(source: FooEntity::class)]
class FooResource
{
public const string uriTemplate = '/v2/foos/{id}';
#[ApiProperty(identifier: true)]
public int $id;
public ?float $amount = null;
#[Map(source: 'relation.bar.name')]
public string $barName;
#[Map(source: 'relation.bar')]
public BarResource $bar;
// ... other mappings
}
2. Related Resource (BarResource)
namespace App\ApiResource\V2\Bar;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\Entity\BarEntity;
use Symfony\Component\ObjectMapper\Attribute\Map;
#[ApiResource(
operations: [
new Get(
uriTemplate: self::uriTemplate
)
],
stateOptions: new Options(entityClass: BarEntity::class)
)]
#[Map(source: BarEntity::class)]
class BarResource
{
public const string uriTemplate = '/v2/bars/{id}';
#[ApiProperty(identifier: true)]
public int $id;
public string $name;
}
What happens?
- Request:
GET /v2/foos?bar=/v2/bars/2 - The
IriConverterParameterProviderorIriFilterexpects a Doctrine entity to build the database query, but since the resource is mapped via Object Mapper, it gets confused by the IRI / mapped resource representation. - The SQL query ends up generating a clause like:
WHERE f0_.bar_id = ?
where the parameter value evaluates to false or fails to link to entity ID 2.
Interestingly, exact filters on simple IDs work fine, and IRI filters on standard non-mapped entity-backed resources work smoothly too. It specifically comes up when combining Object Mapper with IRI-based query parameters.
Any thoughts on whether this is expected limitation right now, or if there's a recommended workaround / bridge we should use? Thanks a lot! 🙌
- 主要语言
- PHP
- 星标
- 2.6k
- 派生
- 988
- 平均合并
- 4 天 10 小时
- 30 天内合并 PR
- 92
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
api-platform/core 的其他 Issue
-
API Platform ignores array shapes in the JSON Schema可能已有人在做 @afraca 于 9 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
api-platform/core#8766 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
api-platform/core#8744 ·
维护者通常 2 天内回复
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1 小时以内 新手友好度 80/100
api-platform/core#8701 ·
维护者通常 2 天内回复
-
难度 5/5 一周以上 新手友好度 30/100
api-platform/core#8791 ·
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
api-platform/core#8790 ·
维护者通常 2 天内回复
查看 api-platform/core 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
Automattic/blocks-engine#4355 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
agentic bug complete-verify
难度 2/5 1-3 小时 新手友好度 85/100
MagnaCapax/PMSS#1234 ·
维护者通常 3 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
yiisoft/yii2-docker#193 ·
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
10up/ElasticPress#4402 ·
维护者通常 2 天内回复