-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DoctrineBridge] Extend type guessing on enum fields #46676
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
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
It looks like you unchecked the "Allow edits from maintainer" box. That is fine, but please note that if you have multiple commits, you'll need to squash your commits into one before this can be merged. Or, you can check the "Allow edits from maintainers" box and the maintainer can squash for you. Cheers! Carsonbot |
I would indeed return |
Doctrine supports enumType on array values. In those cases the guessed type should be of type array with collection information.
Returning |
I also use just |
Actually that's the reason for this PR. There is no way the DoctrineExtractor can guess the correct type from doctrine |
Thank you @Sajito. |
…no Chianese) This PR was merged into the 4.4 branch. Discussion ---------- [DoctrineBridge] Extend type guessing on enum fields | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Doctrine supports enumType on array values, while the current implementation always assumes the value to be an enum object, if enumType is set. If $typeOfField is `json_array` the collectionKeyType will still be null, while collectionValueType will be filled. That's because we have no way to determine from doctrine metadata, if the key is string or int. Yet I don't know if that's a valid thing to do, otherwise we should return null in that case. Commits ------- 79239fe CS fix a9b0f43 [DoctrineBridge] Extend type guessing on enum fields
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]; | ||
return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), $enumType ?? new Type(Type::BUILTIN_TYPE_STRING))]; | ||
} | ||
case Type::BUILTIN_TYPE_INT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have merged to fast here.
@Sajito is the missing break before this line on purpose? Can you please send a PR that adds either the "break" or the "no break" comment, with a test case ideally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have sent a new PR here: #46713.
I didn't know a "no break" comment would be required here, as I took these lines as a reference:
symfony/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Lines 169 to 175 in 7fc7acb
switch ($typeOfField) { | |
case self::$useDeprecatedConstants ? DBALType::DATE : Types::DATE_MUTABLE: | |
case self::$useDeprecatedConstants ? DBALType::DATETIME : Types::DATETIME_MUTABLE: | |
case self::$useDeprecatedConstants ? DBALType::DATETIMETZ : Types::DATETIMETZ_MUTABLE: | |
case 'vardatetime': | |
case self::$useDeprecatedConstants ? DBALType::TIME : Types::TIME_MUTABLE: | |
return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, 'DateTime')]; |
Hope it's fine with the new PR.
This PR was merged into the 4.4 branch. Discussion ---------- [DoctrineBridge] Add missing break ~~This PR only adds the "no break" comment as requested on my last PR:~~ This PR only adds the missing break as requested on my last PR: #46676 (comment) I hope it's fine to not include the describing table. ~~The missing break is on purpose, so here is no real code change.~~ The missing break should not have caused any side effects. I have not changed any tests here, because both cases are already tested by these two lines: https://github.com/symfony/symfony/blob/7fc7acb1e4448762f438af03cadb2ce54e3918e0/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php#L186-L187 Commits ------- 445b78a [DoctrineBridge] Add missing break
It looks like I failed at merging this PR into branch 5.4. There, the added test fails. Could you please have a look @Sajito? Here is the failure on branch 5.4:
|
I created another pull request to fix the issue on the 5.4 branch. |
… Chianese) This PR was merged into the 5.4 branch. Discussion ---------- [DoctrineBridge] Fix value type for simple_array | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Fix for wrong collection value type on `simple_array` after merging the type guessing changes (#46676) into 5.4 branch. Commits ------- 6375990 [DoctrineBridge] Fix value type for simple_array
Doctrine supports enumType on array values, while the current implementation always assumes the value to be an enum object, if enumType is set.
If $typeOfField is
json_array
the collectionKeyType will still be null, while collectionValueType will be filled. That's because we have no way to determine from doctrine metadata, if the key is string or int. Yet I don't know if that's a valid thing to do, otherwise we should return null in that case.