1

我正在尝试将哈希类型用于文档。当我创建一个对象时没有问题,但是当我尝试检索文档时,我得到一个“数组到字符串的转换”。

我已经简化了文档。当我添加这个哈希属性时,这个数组到字符串的转换才开始发生。

查看 symfony 的转储消息,它似乎来自 hydrator。

任何想法为什么 Doctrine 试图将数据转换为字符串?

class MyDocument
{
   /**
    * @MongoDB\Id
    */
   protected $id;

   /**
    * @MongoDB\Field(type="hash")
    */
   protected $value = array();

}

在我的一项服务中的某处:

$product = 
  $this->container->get('doctrine_mongodb')
  ->getRepository('XTradBundle:Traduction')
  ->findAll();

堆栈跟踪:

in var\cache\dev\doctrine\odm\mongodb\Hydrators\WeBSurgTradBundleDocumentTraductionHydrator.php at line 84   -
     if (isset($data['value']) || (! empty($this->class->fieldMappings['value']['nullable']) && array_key_exists('value', $data))) {
        $value = $data['value'];
        if ($value !== null) {
            //Why is it converting it to a string here?
            $return = (string) $value;
        } else {
            $return = null;
        }
4

1 回答 1

0

似乎$valueinprotected $value = array();是一个保留名称。只需将其命名为其他名称即可解决问题。

于 2017-04-28T19:03:40.137 回答