简体   繁体   English

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

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

I'm attempting to use the hash type for a Document. 我正在尝试使用文档的哈希类型。 When I'm creating an object there isn't a problem, but the moment I attempt to retrieve a document, I get an "Array to string conversion". 当我创建一个对象时没有问题,但是当我尝试检索文档时,我得到一个“数组到字符串转换”。

I've simplified the document. 我简化了文件。 This Array to string conversion only started occurring when I added this hash property. 仅当我添加此哈希属性时才开始发生此数组到字符串转换。

Looking at symfony's dump messages, it seems to be coming from the hydrator. 看看symfony的转储消息,它似乎来自保湿器。

Any ideas why Doctrine is attempting to convert the data to a string? Doctrine试图将数据转换为字符串的任何想法?

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

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

}

Somewhere in one of my services: 在我的一项服务中的某个地方:

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

Stack Trace: 堆栈跟踪:

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

Would seem that $value in protected $value = array(); 似乎$value in protected $value = array(); is a reserved name. 是保留名称。 Simply naming it to something else solved the problem. 简单地将其命名为其他东西可以解决问题。

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

相关问题 使用bcrypt.hash时发生未知错误 - Unknown error when using bcrypt.hash 使用 ReactiveMongoDB 更新文档时使用数组过滤器 - Using array filters when updating a document with ReactiveMongoDB 将JSOn字符串转换为Mongo文档的问题 - problem with conversion of JSOn string to Mongo document 使用正则表达式对 mongodb 集合中的文档中的项目数组进行字符串匹配 - String matching using regex for array of items in a document in mongodb collection 日期转换和使用PHP更新mongodb文档 - Date conversion and updating mongodb document using PHP MongoDB:尝试更新作为数组的文档字段时出现“意外令牌”错误 - MongoDB : “unexpected token” error when trying to Update document field that is an array MongoDB不在文档中存储字符串数组 - Mongodb not storing string array in document 通过使用字符串作为任何数组中的第一个对象将数组分隔为对象来更新文档 - Update the document by separating array into objects using the string as first object in any array 在MongoDB中用字符串数组替换嵌入式文档数组 - Replacing embedded document array with a string array in MongoDB 如何在MongoDB文档中的哈希上执行此查询(使用Mongoid) - How to perform this query on a hash in a MongoDB document (using Mongoid)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM