0

我在 Doctrine 2 Repository 函数中有一个奇怪的错误

$query = $this->_em->createQuery('SELECT c FROM \Model\Entity\Cluster c
                                  WHERE c.publisherid = :publisherid');
$query->setParameter("publisherid", (int)$publisher_id);
var_dump($query->getResult());
var_dump($query->getArrayResult());

而我们所拥有的

对象:

array (size=8)
  0 => 
    object(Model\Entity\Cluster)[**396**]
      private 'psiteid' => int 215
      private 'psiteclusterdate' => 
        object(DateTime)[371]
          public 'date' => string '**2011-12-20** 00:00:00' (length=19)
          public 'timezone_type' => int 3
          public 'timezone' => string 'Europe/Moscow' (length=13)
      private 'publisherid' => int 276
      private 'views' => int 14657
      private 'clicks' => int 6220
      ...

  1 => 
    object(Model\Entity\Psitecluster)[**396**]
      private 'psiteid' => int 215
      private 'psiteclusterdate' => 
        object(DateTime)[371]
          public 'date' => string '**2011-12-20** 00:00:00' (length=19)
          public 'timezone_type' => int 3
          public 'timezone' => string 'Europe/Moscow' (length=13)
      private 'publisherid' => int 276
      private 'views' => int 14657
      private 'clicks' => int 6220
      ...

键为 0-3 的行复制此对象 (396),其他行复制第二个对象。当我转储为数组时:

array (size=8)
  0 => 
    array (size=22)
      'psiteid' => int 215
      'psiteclusterdate' => 
        object(DateTime)[367]
          public 'date' => string '**2011-12-20** 00:00:00' (length=19)
          public 'timezone_type' => int 3
          public 'timezone' => string 'Europe/Moscow' (length=13)
      'publisherid' => int 276
      'views' => int 14657
      'clicks' => int 6220
        ....

  1 => 
    array (size=22)
      'psiteid' => int 215
      'psiteclusterdate' => 
        object(DateTime)[396]
          public 'date' => string '2011-12-21 00:00:00' (length=19)
          public 'timezone_type' => int 3
          public 'timezone' => string 'Europe/Moscow' (length=13)
      'publisherid' => int 276
      'views' => int 10166
      'clicks' => int 4028

所有行在数组中都不同。对象有什么问题?

4

1 回答 1

0

我解决了一个问题。这是 Doctrine2 中的一个错误。我在这里创建了错误报告http://doctrine-project.org/jira/browse/DDC-1780

您可以在您的项目中修复(如果您可以编辑 Doctrine 库文件)。只需添加

if ($id[$fieldName] instanceof \DateTime) { 
    $id[$fieldName] = $id[$fieldName]->getTimestamp(); 
}`

在 foreach 循环中。

于 2012-04-16T10:30:24.300 回答