Doctrine 2 Custom Types

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?

+2
php doctrine doctrine2
source share

No one has answered this question yet.

See similar questions:

7
Symfony Doctrine data type only works in findBy not querybuilder
2
Doctrine / Symfony: convert user type to database value before using QueryBuilder

or similar:

250
Doctrine Default Value
8
Entity Doctrine extension for adding business logic
3
Adding a custom data type (geometry) in Doctrine 2.1.7. CanRequireSQLConversion () method not called
one
Neither the parent property will build a Symfony 2 Self-Referenced mapping form
one
Doctrine 2: Oracle Insert Trigger
one
Doctrine 2 DQL Query to Return Filtered Association
one
Extend Function with Doctrine ORM Annotation
one
Doctrine2 + Symfony2 credential table
one
Register a custom Doctrine type in Symfony4
0
Symfony - return type for a Doctrine object

All Articles