-
-
Notifications
You must be signed in to change notification settings - Fork 932
Open
Description
API Platform version(s) affected: since implemented BackedEnumFilter
(#6547), but 4.2.x also
Description
Since doctrine/orm#9497 in doctrine/orm
allows you to save backed enum values in the form of array (for PHP) and in JSON (for PostgreSQL).
Currently, ApiPlatform allows filtering by BackedEnumFilter
when we operate on string/single value only.
However, with the configuration below, filtering no longer works due to JSON type
in Postgresql causes an error:
How to reproduce
<?php
use ApiPlatform\Doctrine\Orm\Filter\BackedEnumFilter;
use ApiPlatform\Metadata\ApiFilter;
use Doctrine\DBAL\Types\Types;
use App\NotificationTypeEnum;
#[ApiFilter(filterClass: BackedEnumFilter::class, properties: ['notificationTypeEnums'])]
class Notification {
/** @var non-empty-list<NotificationTypeEnum>|null */
#[ORM\Column(name: 'notification_type_enums', type: Types::JSON, nullable: true, enumType: NotificationTypeEnum::class, options: ['jsonb' => true, 'comment' => 'Enumeric Values of Notification Type.'])]
public array|null $notificationTypeEnums = null {
get => $this->notificationTypeEnums;
set => $this->notificationTypeEnums = $value;
}
}
Possible Solution
- https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/Filter/BackedEnumFilter.php#L164 check if field mapping is setup to be
JSON/array
and ignore then - https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/Filter/BackedEnumFilter.php#L148 add support by using non available functions in
doctrine/orm
likejsob_*
- it may be impossible to add
Additional Context
Called database SQL:
SELECT count(DISTINCT n0_.notification_id) AS sclr_0 FROM notification n0_ WHERE (n0_.notification_type_enums IN ('NOTIFICATION', 'EMAIL'));
Metadata
Metadata
Assignees
Labels
No labels