【发布时间】:2015-04-09 15:59:12
【问题描述】:
我正在使用 Symfony 2.6 构建一个小项目。它非常简单,只有一个实体类映射到使用在 Raspberry Pi 上运行的 python 插入 MySQL 数据库的数据。
问题
当我运行这个简单的存储库查询时,结果集似乎被转换为导致错误的数组(如下)。我不确定为什么会发生这种转换。
回购方式
public function getDataInRange( \DateTime $from, \DateTime $until)
{
$query = $this->getEntityManager()->createQuery('
select d
from AppBundle:weatherdata d
where d.idx > :f
and d.idx < :u ')->setParameters(array( 'f' => $from, 'u' => $until ));
return $query->getResult();
}
错误
Catchable Fatal Error: Object of class DateTime could not be converted to string
数据库结构
主键,'idx' 是 datetime 对象,其他都是 double。
试过了..
我尝试将 repo 方法更改为返回 getArrayResult(),这会停止错误,但我需要将结果集设为对象格式,因为我需要对数据进行其他处理。
提前致谢。
【问题讨论】:
标签: php symfony doctrine-orm