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

redefine ENUMs with enumType #212

Open
arhimede opened this issue Jan 10, 2024 · 2 comments
Open

redefine ENUMs with enumType #212

arhimede opened this issue Jan 10, 2024 · 2 comments
Assignees

Comments

@arhimede
Copy link
Member

https://www.doctrine-project.org/projects/doctrine-orm/en/2.17/cookbook/mysql-enums.html

https://stackoverflow.com/questions/73907769/how-to-mapping-type-enums-in-doctrine

@alexmerlin please give us an idea here if we should replace enum with enumType

@alexmerlin
Copy link
Member

Solution 1: Mapping to Varchars is what we're currently using and as we know, it has it's own flaws (showing unnecessary modifications in each migration).

Solution 2: Defining a Type seems to be the preferred approach in most frameworks.
In addition to the method described in the article, there should be either:

  1. An abstract type that then could be extended by each custom enumType

    abstract class AbstractEnumType extends Type containing all the methods defined in the article (getSQLDeclaration, convertToPHPValue etc)
    Then custom enumTypes extending AbstractEnumType that have only one purpose, providing the values (which can be defined as constants in the custom enumType and also used in the $values array - this way the values are defined only once and constants can also be reused outside the class)

  2. One single enumType that when added to a property, can be configured (if needed, the values parameter's name can be changed to a more suitable one):

    #[ORM\Column(name: "status", type: EnumType::class, values: ["pending", "active"])]
    If this can be implemented, it would be the easisest solution both to write and to use.

Note:
Both solutions (the abstract / generic enumTypes) are theoretical, I did not try them in practice. Their purpose is only to give an idea on where to start implementing these types.

@arhimede
Copy link
Member Author

@kakapiciu will try to implement a proof of concept
solution 2, variant #2

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

No branches or pull requests

4 participants