Skip to content

Enums

Formal natively support enums as a property and inside collections (1).

  1. Via Sets.

This means you don't need to create custom types for each enum in your project, it just works.

Info

Formal uses the case name as the value persisted in the storage. Even when you use backed enums.

In order to search aggregates having an enum case inside a collection you can use this specification:

use Formal\ORM\Specification\Child\Enum;

Enum::any(
    'collectionPropertyName',
    YourEnum::someCase,
)

This will return the aggregate if this case is present in the collection.

use Formal\ORM\Specification\Child\Enum;

Enum::in(
    'collectionPropertyName',
    YourEnum::someCase,
    YourEnum::someOtherCase,
)

This will return the aggregate if one of the cases is present in the collection.