-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix enum hydration when fetching partial results #9657
Conversation
I suggest the following: in AbstractHydrator use: case isset($cacheKeyInfo['isScalar']):
$type = $cacheKeyInfo['type'];
if (isset($cacheKeyInfo['enumType'])) {
$value = $type->convertToPHPEnumValue($value, $this->_platform, $cacheKeyInfo['enumType']);
} else {
$value = $type->convertToPHPValue($value, $this->_platform);
}
$rowData['scalars'][$fieldName] = $value;
break; And in DBAL extend the /**
* Converts a value from its database representation to its PHP enum representation
* of its type
*
* @param mixed $value The value to convert
* @param AbstractPlatform $platform
* @param string $enumType
* @return BackedEnum
* @throws ConversionException
*/
public function convertToPHPEnumValue($value, AbstractPlatform $platform, $enumType)
{
try {
return $enumType::from($value);
}catch(ValueError $error){
throw new ConversionException("Cannot convert value to PHP enum", 0, $error);
}
} This will work well for most types. I will overload the method in those, where it would be problematic, such as If somebody wants to have PHP enum support in their type, they can overload this method too. There is no BC break. |
This is a good fix given our current data structures. It shows though that our reflection and type apis are not the best abstraction anymore. I was thinking about something new for ORM 3 but had no time sofar. For 2.x we can use this approach |
@beberlei So can I make the DBAL PR? I need it merged there before I can finish this in ORM, otherwise tests will fail. |
I am reviewing on mobile phone, the current patch looks like it can work without dbal changes? The fix must be orm only |
The current fix has the limitations which I described, it will ONLY work with string type. If we use |
Couldnt you switch over the scalar type inside the enumMappibngs case and reimplement the simple array case? We are already in workaround mode here so local patching is fine. Add a comment that it reimplements the ReflectionEnumPriperty code there |
I can and it was my first approach, but we will fix only these 2 cases. I realized |
This is ready for merge. @beberlei please review |
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.
Go from overall implementation pov, havent reviewed style and other non functional requirements.
Co-authored-by: Alexander M. Turek <[email protected]>
Thank you @michnovka! |
This is the first attempt to fix the issue #9622