Skip to content

SearchFilter shouldn't rely on nested resources having an "id" field #5605

@mrossard

Description

@mrossard

API Platform version(s) affected: 3.1.12

Description
When you use a SearchFilter on a nested property that is a resource and doesn't use "id" as its identifier you get "Can't get a way to read the property "id" in class XXX".

How to reproduce
Have 2 resources A and B, with A containing a B (both simple ApiResources using entityClass=... in my case)
Use an ApiIdentifier in B that is not "id", ie IRIs are /Bs/{someotherfield}.
Add a searchfilter for the B member on A :

#[ApiFilter(SearchFilter::class, properties:['b'])

Possible Solution
Didn't have time to dig into this yet, but it's happening in SearchFilterTrait line 127 :

return $this->getPropertyAccessor()->getValue($item, 'id');

This should probably be replaced so it at least looks for id in the entityClass when present, or even tries to get the ORM to return the correct id(s) without hard coding it.

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