Allow DiscriminatorColumn with length=0 #9410
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch allows to set
length
to a Zero-Value on a@ORM\DiscriminatorColumn
:Right now a value <1 will be replaced by the default value (255) of a ternary operation in
\Doctrine\ORM\Mapping\Driver\AnnotationDriver::loadMetadataForClass
.This seems to be an accidental results from the weak type comparison.
On a
@ORM\Column
a length of Zero will be parsed as is and not changed to 255.Background:
I'm mapping MySQL enums to strings as described here: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/mysql-enums.html#solution-1-mapping-to-varchars
Since the 3.2 release with the new Platform-aware schema comparison (
https://www.doctrine-project.org/2021/11/26/dbal-3.2.0.html) I get a lot of diffs in our enum fields.
The schema diff will report different values for the
length
-property as the MySQl Platform yields lenght = 0 for the mysql native ENUM type.To fix the diff the length has to be specified as 0:
This works for all columns and the enum fields won't generate diffs anymore.
The same lenght=0 change is required if the DiscriminatorColumn uses a native Enum type like so:
Right now this is not possible as
length=0
on aDiscriminatorColumn
will becomelength=255
and thus a diff will be reported from the schema comparison.