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

Auto-detect values for EnumType columns #11666

Merged
merged 1 commit into from
Oct 12, 2024

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Oct 12, 2024

Follow-up to #11657, leverages doctrine/dbal#6536.

This PR allows us to detect the enumType and options.values settings for a typed property with type: Types::ENUM.

Before:

#[Entity]
class Card
{
    #[Id]
    #[GeneratedValue]
    #[Column]
    public int $id;

    #[Column(
        type: Types::ENUM,
        enumType: Suit::class,
        options: ['values' => ['H', 'D', 'C', 'S']],
    )]
    public Suit $suit;
}

After:

#[Entity]
class Card
{
    #[Id]
    #[GeneratedValue]
    #[Column]
    public int $id;

    #[Column(type: Types::ENUM)]
    public Suit $suit;
}

Note that the type: Types::ENUM part is still required if we want to have an actual ENUM column in MySQL/MariaDB. We still default to Types::STRING or TYPES::INTEGER for columns types with a PHP enum as this is the more portable solution and the safer default.

@derrabus derrabus added this to the 3.3.0 milestone Oct 12, 2024
beberlei
beberlei previously approved these changes Oct 12, 2024
@greg0ire
Copy link
Member

Probably not the first PR on which I should have noted this, but should https://github.com/doctrine/orm/blob/3.2.x/docs/en/cookbook/mysql-enums.rst get modifications about this?

@derrabus
Copy link
Member Author

Yeah, that whole page needs an overhaul now.

@derrabus
Copy link
Member Author

Let's do this in a follow-up though. This is a larger change.

@derrabus
Copy link
Member Author

I've opened #11668 to track the documentation issue.

@derrabus derrabus merged commit 60c2454 into doctrine:3.3.x Oct 12, 2024
86 checks passed
@derrabus derrabus deleted the feature/enum-type branch October 12, 2024 15:36
@whataboutpereira
Copy link

Thank you for all your work! Great timing also as I've been looking for ways around enums the past few weeks, but now they simply work. :)

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

Successfully merging this pull request may close these issues.

4 participants