我正在尝试为MongoDB ODM实体使用ReferenceOne,但随后生成了Doctrine Hydrator文件,返回以下错误:
致命错误:无法使用MongoId类型的对象作为数组 /var/www/project/data/DoctrineMongoODMModule/Hydrator/ApplicationDocumentTokenEntryHydrator.php
以下是相关财产的定义:
/**
* Page Mongo Id from Pages entry
*
* @ODM\Field(name="pageInternalId", type="object_id")
* @ODM\ReferenceOne(targetDocument="Page\Document\PagesEntry")
* @var \MongoId
*/
protected $pageInternalId;
我在生成的Hydrator和DoctrineODMModule中挖了一点,发现以下代码片段是问题
if (isset($this->class->fieldMappings['pageInternalId']['simple']) && $this->class->fieldMappings['pageInternalId']['simple']) {
$className = $this->class->fieldMappings['pageInternalId']['targetDocument'];
$mongoId = $reference;
} else {
$className = $this->unitOfWork->getClassNameForAssociation($this->class->fieldMappings['pageInternalId'], $reference);
**$mongoId = $reference['$id'];**
}
由于某种原因,fieldMapping不被视为/设置为“简单” - 如果我理解正确,如果我可以这样设置它,它将进入第一个子句并且应该正常工作。但是,我在Doctrine documentation中没有找到任何关于将属性设置为“简单”的内容。如何确定该值,是否可以在定义属性时设置?
我离开了无关的(imho)部分,如果需要更多信息,我会提供。提前谢谢!
我正在使用DoctrineODMModule 0.9.1
答案 0 :(得分:0)
该字段应该映射为@ReferenceOne
或@Field
- 将这两者结合起来可能是问题的罪魁祸首。除此之外,映射为@ReferenceOne
的属性将包含一个引用的对象(从代码的角度来看,在数据库中它实际上是MongoID
但是你不需要关心它,因为它是ODM的任务)。