Created
March 13, 2013 09:37
-
-
Save norberttech/5150573 to your computer and use it in GitHub Desktop.
Doctrine DateTime2 mapping problem. (MSSQL server will accept it if there will be 3 digits only after dot)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace FSi\Bundle\DemoBundle\Doctrine\DBAL\Types; | |
use Doctrine\DBAL\Types\VarDateTimeType; | |
use Doctrine\DBAL\Types\Type; | |
use Doctrine\DBAL\Platforms\AbstractPlatform; | |
class Datetime2Type extends VarDateTimeType | |
{ | |
public function canRequireSQLConversion() | |
{ | |
return true; | |
} | |
public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) | |
{ | |
return sprintf('CONVERT(datetime2, %s)', $sqlExpr); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace FSi\Bundle\DemoBundle; | |
use Symfony\Component\HttpKernel\Bundle\Bundle; | |
class DemoBundle extends Bundle | |
{ | |
public function boot() | |
{ | |
Type::overrideType('datetime', 'FSi\Bundle\DemoBundle\Doctrine\DBAL\Types\Datetime2Type'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the solution.