I would like to use Carbon objects in my Symfony 3.2 application instead of the SPL \DateTime object. I found a set of DoctrineExtension classes in here.
Edited my config.yml file:
doctrine:
dbal:
...
types:
carbondatetime: DoctrineExtensions\Types\CarbonDateTimeType
carbondate: DoctrineExtensions\Types\CarbonDateType
carbontime: DoctrineExtensions\Types\CarbonTimeType
mapping_types:
datetime: carbondatetime
date: carbondate
enum: string
time: carbontime
I successfully check if the types are loaded with:
Doctrine\DBAL\Types\Type::getTypesMap()
And the mapping as well is working properly (returns carbondatetime
):
$this->getDoctrine()->getManager()
->getConnection()->getDatabasePlatform()
->getDoctrineTypeMapping('datetime');
I execute a query over a Doctrine repository and still get DateTime objects. It is working in 2 cases:
@ORM\Column(type="carbondatetime")
\Doctrine\DBAL\Types\Type::overrideType('datetime', 'DoctrineExtensions\Types\CarbonDateTimeType');
Is there a Best-Practice to override the Doctrine DBAL types? Preferably in the YAML configuration.
Thanks
Woah.... Like always, as soon you ask the question you find the solution:
doctrine:
dbal:
...
types:
datetime: DoctrineExtensions\Types\CarbonDateTimeType
date: DoctrineExtensions\Types\CarbonDateType
time: DoctrineExtensions\Types\CarbonTimeType
mapping_types:
enum: string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With