acelaya / doctrine-enum-type

A custom Doctrine type that maps column values to enum objects using myclabs/php-enum
MIT License
132 stars 15 forks source link

Save to db key, instead of value #49

Closed antonioturdo closed 4 years ago

antonioturdo commented 4 years ago

Is there any reason not to save the key in the db instead of the value?

If I want to create an enumeration to populate a drop-down menu on a web page, I would like to be able to represent the options visible to the user as strings, even long ones, with spaces and other characters (which cannot be used as names of constants in PHP ), but save a shorter representation in the db.

For example:

class Reply extends Enum
{
    public const YES = "Yes, I'm ready to accept";
    public const NO = "No, I am not still ready";
}
acelaya commented 4 years ago

No, there's no particular reason, but it's something that cannot be changed now without introducing a breaking change.