Skip to content

[ORM] BackedEnumFilter not respects array of enum values. #7362

@michaljusiega

Description

@michaljusiega

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

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'));

Exception in profiler.
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions