繁体   English   中英

在Document中使用哈希时出现“数组到字符串转换”错误

[英]“Array to string conversion” error when using hash in Document

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

我简化了文件。 仅当我添加此哈希属性时才开始发生此数组到字符串转换。

看看symfony的转储消息,它似乎来自保湿器。

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;
        }

似乎$value in protected $value = array(); 是保留名称。 简单地将其命名为其他东西可以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM