Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
whataboutpereira opened this issue Jan 18, 2025 · 4 comments

Comments

@whataboutpereira
Copy link

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
@derrabus derrabus transferred this issue from doctrine/migrations Jan 18, 2025
@derrabus derrabus changed the title MySQL80Platform requires the values of a ENUM column to be specified when using enum DiscriminatorColumn. MySQL80Platform requires the values of a ENUM column to be specified when using enum DiscriminatorColumn Jan 21, 2025
@derrabus
Copy link
Member

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?

whataboutpereira added a commit to whataboutpereira/doctrine-orm that referenced this issue Jan 23, 2025
whataboutpereira added a commit to whataboutpereira/doctrine-orm that referenced this issue Jan 23, 2025
@whataboutpereira
Copy link
Author

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.

@derrabus
Copy link
Member

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.

@whataboutpereira
Copy link
Author

Added tests now as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants