Open
Description
API Platform version(s) affected: 4.1.18
Description
I believe that filtering by relation fields using dot notation (as per the JSON:API specification) should work out of the box. However, it seems like this functionality is either not implemented or not working correctly, as attempting such a filter results in an error.
#[
ApiResource(
uriTemplate: '/posts',
operations: [
new GetCollection(
parameters: [
new QueryParameter(
key: 'filter[author.name]',
filter: PartialSearchFilter::class,
property: 'author.name',
),
],
),
],
),
]
class Post extends Model
{
public function author()
{
return $this->belongsTo(User::class);
}
}
class User extends Model
{
// ...
}
Assuming this relationship is correctly exposed in the API, I would expect the following filter to work:
/api/posts?filter[author.name]=John
But instead, this request results an error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'author.name' in 'where clause' (Connection: mariadb, SQL: select count(*) as aggregate from
posts
whereauthor
.name
like %John%)
Metadata
Metadata
Assignees
Labels
No labels