【发布时间】:2014-11-27 08:18:00
【问题描述】:
我正在尝试使用日期作为主键来创建实体。问题是 Symfony 无法将我使用的 DateTime 转换为字符串以将其引入 IdentityMap。在实体持久化过程中出现以下错误:
Catchable Fatal Error: Object of class DateTime could not be converted to string in..
我在实体中使用此代码:
/**
* @ORM\Id
* @ORM\Column(type="datetime")
*/
protected $date;
实体仓库中出现错误:
$em = $this->getEntityManager();
$currentData = new CurrentData();
...
$currentData->setDate(new \DateTime($dateStr));
...
$em->persist($currentData);
$em->flush();
我该如何解决这个问题?谢谢。
【问题讨论】:
标签: datetime symfony doctrine primary-key