Skip to content

IriFilter doesn't work with custom ApiProperty identifier attribute #7913

@Julbert123

Description

@Julbert123

API Platform version(s) affected: 4.3.0

Description
If a custom identifier is set with the ApiProperty attribute, setting an IriFilter in another class and using the filter with an IRI like "/classa/<custom_id>" does not return any result but "/classa/<db_id>" does (even if this IRI doesn't exist)

How to reproduce
Use doctrine ODM
Create ClassA with a ReferenceOne to ClassB
Cerate a field with #[ApiProperty(identifier: true)] on another field than the #[Id] in ClassB
Create some ClassA and ClassB entries
Set an IriFilter on the reference property in ClassA
Call API with this filter and a filter value including a custom ID which is referenced by at least one object => It doesn't return any result
Call API with this filter and a filter value including a real ID (ObjectId) which is referenced by at least one object => It returns one or more result

Additional Context
Mail.php

#[ApiResource(operations: [
    new GetCollection(parameters: [
        'author' => new QueryParameter(filter: new IriFilter()),
    ]),
])]
#[Document]
class Mail
{
    #[Id]
    private ?string $id = null;

    #[ReferenceOne(targetDocument: Agent::class, storeAs: 'id')]
    private ?Agent $author = null;

  // ...
}

Agent.php

#[ApiResource(operations: [
    new Get(),
])]
#[Document(repositoryClass: AgentRepository::class)]
class Agent
{
    #[Id]
    #[ApiProperty(identifier: false)]
    private ?string $id = null;

    #[Field]
    #[ApiProperty(identifier: true)]
    private ?string $agentId = null;

  // ...
}
Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions