Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 2.1.6
-
Fix Version/s: None
-
Component/s: DQL
-
Security Level: All
-
Labels:None
Description
Maybe I am doing something wrong, but here is the case:
I created a custom Doctrine Type:
class BinaryType extends Type { const BINARY = 'binary'; public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return sprintf('BINARY(%d)', $fieldDeclaration['length']); } public function getName() { return self::BINARY; } public function convertToPhpValue($value, AbstractPlatform $platform) { if ($value !== null) { $value= unpack('H*', $value); return array_shift($value); } } public function convertToDatabaseValue($value, AbstractPlatform $platform) { if ($value !== null) { return pack('H*', $value); } } }
Now I have a simple table with Photographerguid field as binary (the custom type created) and run a simple query:
$q = $repository->createQueryBuilder('p')->select('p.name, p.surname, p.photographerguid')->where("p.name = 'peter'");
$result = $q->getQuery()->getResult();
The function convertToPhpValue is not run on the value of Photographerguid, so it returns %&@#!((@#
The reason is that in AbstractHydrator::_gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents) function
all fields of a query are determined as scalar (isScalar), and convertToPHPValue($value, $this->_platform) is not run on them.
What is the difference between scalarMappings and fieldMappings?
How to make data conversion work in both directions?