I am trying to implement the Datatype Doctrine Custom to store decimal places in dollars as an integer SQL. I cannot change the design of the database, so I have to:
<?php namespace Doctrine\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; class Currency extends Type { const CURRENCY = 'currency'; const DECIMALS = 2; public function getName() { return self::CURRENCY; } public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return $platform->getDoctrineTypeMapping('CURRENCY'); } public function convertToPHPValue($value, AbstractPlatform $platform) { return ($value / pow(10, self::DECIMALS)); } public function convertToDatabaseValue($value, AbstractPlatform $platform) { return (int) ($value * pow(10, self::DECIMALS)); } } ?>
This works fine if I load the EntityRepository object "find" method. But this does not work if you use the "UPDATE" DQL statements. What can I do to make this work in DQL instructions too?
php doctrine doctrine2
user2798515
source share