Open michnovka opened 2 years ago
Sounds reasonable, especially if we want to support backed enumerations as discriminators.
This will require redesign of internal ClassMetadataInfo::$discriminatorMap
as right now it also uses same structure with array key being the actual discriminator. Thats a public property, so there is a BC break. Otherwise wed have to copy lot of code to handle this special case, to keep BC.
@beberlei would like your input on this too, please.
How about we call the getDatabaseValue
when constructing the discriminator map? And then when it is inserted into SQL, we no longer need to do that. This would allow us to keep the same ClassMetadataInfo::$discriminatorMap
. I dont think BC would be broken, as currently it cannot work for any non-scalar types, and those have the same PHP value as DB value
is it at all possible to have php 8.1 enums as discriminator maps? I tried using the ->value method but it gives Constant expiression contains invalid operations.
@Gabb1995 this question does not belong here, but since you already asked, the answer is no. Using Enum::enumCase->value
inside attributes is a PHP 8.2 feature.
Feature Request
I have a custom DBAL type and I wish to use it as a discriminator column for JOINED inheritance type
Summary
In my case I use custom type that works with enums. But any custom type using any non-scalar PHP value would cause the same issues:
The issue is that while any type can be used for
DiscriminatorColumn
, theDiscriminatorMap
definition accepts only format likeThe
VALUE_OF_COLUMN
is the actual PHP value used by theType
thats converted to DB value withType::convertToDatabaseValue()
.And here lies the problem
in PHP as of 8.1 we cannot use objects as array keys. Therefore no objects / enums can be used inside
DiscriminatorMap
solely for this limitation. TheJoinedSubclassPersister
handles the conversion through DBAL Type correctly, but the PHP limitation makes it impossible to use any non-scalar keys.Proposed solution
I propose an alternative declaration of
DiscriminatorMap
, but keep the old one for simplicity and BC.So my code would look:
This would allow any custom type to be used as discriminator