Skip to content

[Filters] Improve filter compatibility with stateOptions #7610

@KDederichs

Description

@KDederichs

Description

I'm currently mapping my ApiResources to the underling Doctrine entities using stateOptions.

If your api properties have the same name as the underlying Doctrine entity, all is well.

The problem begins if the name is different, or worse if the underlying entity fetches that property from a related entity.

As far as I can tell you are filtering out any properties that aren't directly accessible via the ApiResource which leaves me with the problem of not being able to filter on those properties, since they do not exist on the entity in that case.

As for how to fix this:

I thought maybe it would make sense to be able to map the public facing resource to what ever property is responsible for providing the value.

Example

My first thought was you could maybe do something like this:

#[GetCollection(
    parameters: [
        'search[:property]' => new QueryParameter(
            filter: new PartialSearchFilter(),
            properties: [
                'foo' => 'bar.foo'
            ],
            filterContext: SearchFilterInterface::STRATEGY_IPARTIAL
        ),
        'order[:property]' => new QueryParameter(
            filter: new OrderFilter(),
            properties: [
                'createdAt'
            ],
            filterContext: OrderFilterInterface::DIRECTION_DESC
        )
    ]
)]

where you specify the (nested) property on the underlying entity as second parameter in the properties configuration.

That way the front facing API is still clean and we could gain more control on how to filter stuff.

@soyuka let me know if that's indeed how it's currently working please and if you'd be fine with a solution like that.
If it is and you are I'll try to provide a PR to add this.

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