Skip to content

PartialSearchFilter and ExactFilter don't discover property name of filter with :property placeholder #7478

Description

@dlubitz

API Platform version(s) affected: 4.2.2

Description
If I try to use the new ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter or ApiPlatform\Doctrine\Orm\Filter\ExactFilter in combination of a :property placeholder as the example in the docs , the filters throw an exception, as the property name is null.

If I add one of the filter directly to a parameter, the filter works fine.

How to reproduce

<?php
// api/src/Resource/Book.php

#[ApiResource(operations: [
    new GetCollection(
        parameters: [
            // This WILL restrict to only title and author properties
            'search[:property]' => new QueryParameter(
                properties: ['title', 'author'], // Only these properties get parameters created
                filter: new PartialSearchFilter()
            )
        ]
    )
])]
class Book {
    // ...
}

Exception:

ApiPlatform\\Doctrine\\Orm\\Util\\QueryNameGenerator::generateParameterName(): Argument #1 ($name) must be of type string, null given, called in /var/www/html/backend/vendor/api-platform/doctrine-orm/Filter/PartialSearchFilter.php on line 37

https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/Filter/PartialSearchFilter.php#L31-L37

Possible Solution
T.B.D.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions