set doctrine type "date interval" using native postgresql date interval

This commit is contained in:
Julien Fastré 2018-04-16 11:53:39 +02:00
parent 0287da70d7
commit 7fb2084506
2 changed files with 36 additions and 0 deletions

View File

@ -141,6 +141,15 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
)
));
//add dbal types (default entity_manager)
$container->prependExtensionConfig('doctrine', array(
'dbal' => [
'types' => [
'dateinterval' => \Chill\MainBundle\Doctrine\Type\NativeDateIntervalType::class
]
]
));
//add current route to chill main
$container->prependExtensionConfig('chill_main', array(
'routing' => array(

View File

@ -0,0 +1,27 @@
<?php
namespace Chill\MainBundle\Doctrine\Type;
use Doctrine\DBAL\Types\DateIntervalType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* Re-declare the date interval to use the implementation of date interval in
* postgreql
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class NativeDateIntervalType extends DateIntervalType
{
public function getName(): string
{
return \Doctrine\DBAL\Types\Type::DATEINTERVAL;
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return 'INTERVAL';
}
}