orm icon indicating copy to clipboard operation
orm copied to clipboard

MySQL80Platform requires the values of a ENUM column to be specified when using enum DiscriminatorColumn

Open whataboutpereira opened this issue 1 year ago • 4 comments

Using enum in DiscriminatorColumn:

enum CommentType: string
{
    case One = 'one';
    case Two = 'two';
    case Three = 'three';
}
#[ORM\DiscriminatorColumn(name: 'Type', type: Types::ENUM, enumType: CommentType::class)]
#[ORM\DiscriminatorMap([
    'one' => CommentOne::class,
    'two' => CommentTwo::class,
    'three' => CommentThree::class,
])]

When generating a migration, this yields:

Doctrine\DBAL\Platforms\MySQL80Platform requires the values of a ENUM column to be specified.

I see AbstractMySQLPlatform.php->getEnumDeclarationSQL() receives these (first one has values populated, second one has no values, but enumType is specified, that the first one doesn't have):

Array
(
    [name] => Type
    [type] => Doctrine\DBAL\Types\EnumType Object
        (
        )

    [default] =>
    [notnull] => 1
    [length] => 0
    [precision] =>
    [scale] => 0
    [fixed] =>
    [unsigned] =>
    [autoincrement] =>
    [comment] =>
    [values] => Array
        (
            [0] => one
            [1] => two
            [2] => three
        )

    [version] =>
)
Array
(
    [name] => Type
    [type] => Doctrine\DBAL\Types\EnumType Object
        (
        )

    [default] =>
    [notnull] => 1
    [length] => 255
    [precision] =>
    [scale] => 0
    [fixed] =>
    [unsigned] =>
    [autoincrement] =>
    [comment] =>
    [values] => Array
        (
        )

    [enumType] => App\Enum\CommentType
    [version] =>
)
doctrine/dbal                       4.2.2
doctrine/migrations                 3.8.2
doctrine/orm                        3.3.1

whataboutpereira avatar Jan 18 '25 11:01 whataboutpereira

We indeed don't support extracting the enum cases in discriminator columns yet, but I don't see why we shouldn't. Do you want to work on this feature?

derrabus avatar Jan 21 '25 09:01 derrabus

We indeed don't support extracting the enum cases in discriminator columns yet, but I don't see why we shouldn't. Do you want to work on this feature?

It turned out easier to get working than I expected. I'm not sure how to go about testing it though.

whataboutpereira avatar Jan 23 '25 09:01 whataboutpereira

You can have a look at our existing functional test suite. You would basically create an entity model that reproduces your problem and write code that persists and fetches data using that model.

derrabus avatar Jan 23 '25 11:01 derrabus

Added tests now as well.

whataboutpereira avatar Jan 24 '25 16:01 whataboutpereira