Symfony 自定义学说日期时间类型不起作用
Symfony custom doctrine datetime type not working
我有以下配置,我尝试在 2005 兼容模式下处理 SQL Server 2008 运行,日期时间怪癖。
=== config.yml
# Doctrine Configuration
doctrine:
dbal:
types:
datetime2005: AppBundle\ORM\DBAL\DateTime2005Type
=== DateTime2005Type.php
namespace AppBundle\ORM\DBAL;
use Doctrine\DBAL\Types\DateTimeType as BaseDateTimeType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class DateTime2005Type extends BaseDateTimeType
{
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
die();
}
}
请注意这里的 die()。它应该停止执行我的应用程序,对吗?
=== SomeEntity.php
/**
* @ORM\Column(name="ErzDate", type="datetime2005", nullable=true)
*/
private $createdAt;
ss
=== Rendered SQL & error:
An exception occurred while executing 'SELECT count(DISTINCT m0_.Ident) AS sclr0 FROM MedionOA3Requests m0_ WHERE m0_.Project LIKE ? AND m0_.ErzDate IS NOT NULL AND m0_.ErzDate >= ?' with params ["MANUALQUERY", "2016-02-13 00:00:00"]:
SQLSTATE [22007, 242]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Bei der Konvertierung eines nvarchar-Datentyps in einen datetime-Datentyp liegt der Wert außerhalb des gültigen Bereichs.
所以我的自定义日期时间没有加载,或者我实施错误。请帮忙。
- 注册自定义学说类型的正确配置是什么?
- 我应该(重新)实现哪些功能才能使 Doctrine 使用自定义
日期时间格式?
自定义类型仅适用于持久化和 select 表达式,不适用于 WHERE
子句。这意味着对象将在水合后具有转换值。
When using DQL queries, the convertToPHPValueSQL and convertToDatabaseValueSQL methods only apply to identification variables and path expressions in SELECT clauses. Expressions in WHERE clauses are not wrapped!
If you want to use Point values in WHERE clauses, you have to implement a user defined function.
也许你可以按照他们的建议using a custom function解决。
我有以下配置,我尝试在 2005 兼容模式下处理 SQL Server 2008 运行,日期时间怪癖。
=== config.yml
# Doctrine Configuration
doctrine:
dbal:
types:
datetime2005: AppBundle\ORM\DBAL\DateTime2005Type
=== DateTime2005Type.php
namespace AppBundle\ORM\DBAL;
use Doctrine\DBAL\Types\DateTimeType as BaseDateTimeType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class DateTime2005Type extends BaseDateTimeType
{
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
die();
}
}
请注意这里的 die()。它应该停止执行我的应用程序,对吗?
=== SomeEntity.php
/**
* @ORM\Column(name="ErzDate", type="datetime2005", nullable=true)
*/
private $createdAt;
ss
=== Rendered SQL & error:
An exception occurred while executing 'SELECT count(DISTINCT m0_.Ident) AS sclr0 FROM MedionOA3Requests m0_ WHERE m0_.Project LIKE ? AND m0_.ErzDate IS NOT NULL AND m0_.ErzDate >= ?' with params ["MANUALQUERY", "2016-02-13 00:00:00"]:
SQLSTATE [22007, 242]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Bei der Konvertierung eines nvarchar-Datentyps in einen datetime-Datentyp liegt der Wert außerhalb des gültigen Bereichs.
所以我的自定义日期时间没有加载,或者我实施错误。请帮忙。
- 注册自定义学说类型的正确配置是什么?
- 我应该(重新)实现哪些功能才能使 Doctrine 使用自定义 日期时间格式?
自定义类型仅适用于持久化和 select 表达式,不适用于 WHERE
子句。这意味着对象将在水合后具有转换值。
When using DQL queries, the convertToPHPValueSQL and convertToDatabaseValueSQL methods only apply to identification variables and path expressions in SELECT clauses. Expressions in WHERE clauses are not wrapped! If you want to use Point values in WHERE clauses, you have to implement a user defined function.
也许你可以按照他们的建议using a custom function解决。