无法在任何时间获取引用的实体属性,仅在渲染方法中

时间:2015-02-14 18:30:47

标签: php mongodb doctrine doctrine-odm doctrine-mongodb

/** @ODM\Document(collection="Entities") */
class Entity extends Document {

    /** @ODM\Id */
    protected $_id;

    /** @ODM\ReferenceOne(targetDocument="\Doctrine\Documents\Entities\Entity2", simple=true) */
    protected $entity2;
}

/** @ODM\Document(collection="Entities2") */
class Entity2 extends Document {

    /** @ODM\Id */
    protected $_id;

    /** @ODM\String */
    protected $label;
}

我的问题是,当我调用引用的实体$entity->getEntity2()时,它会返回entity2,但会返回public $__isInitialized__ => bool(false)。然后,当我尝试拨打$entity->getEntity2()->getId()时,它会抛出Doctrine\ODM\MongoDB\DocumentNotFoundException The "Proxies\__CG__\Doctrine\Documents\Entities\Entity2" document with identifier "54de5341642c8769150041a7" could not be found.

奇怪的是,当我在我的框架中渲染之前调用它时会发生这种情况。当我在渲染方法中执行相同操作时,它可以工作,但它不能用于表单提交处理方法......

我已经清理了缓存,代理和水合器。具有此ObjectID的文档位于我的数据库中并且它被返回,只是没有初始化并且除了渲染方法之外无法获取任何属性

通过调用getEntity2()(介意$__isInititalized = false

返回此消息
  

class Proxies__CG __ \ Doctrine \ Documents \ Entities \ Entity2#178(6){   public $ 初始值设定项 =>关闭#160(3){public $ static =>   array(2){'documentPersister'=>类   Doctrine \ ODM \ MongoDB \ Persisters \ DocumentPersister#166(11){...}   'reflectionId'=> class ReflectionProperty#165(2){...}} public   $ this => class Doctrine \ ODM \ MongoDB \ Proxy \ ProxyFactory#78(7){   private $ metadataFactory =>类   Doctrine \ ODM \ MongoDB \ Mapping \ ClassMetadataFactory#74(9){...}   private $ uow => class Doctrine \ ODM \ MongoDB \ UnitOfWork#76(23){...}   private $ proxyNamespace => string(7)“Proxies”private $ proxyGenerator   => class Doctrine \ Common \ Proxy \ ProxyGenerator#79(4){...} private $ autoGenerate => int(1)private $ definitions =>数组(1){...}   private $ metadataFactory =>类   Doctrine \ ODM \ MongoDB \ Mapping \ ClassMetadataFactory#74(9){...}}   public $ parameter => array(1){'$ proxy'=> string(10)“”}} public   $ 克隆 =>关闭#170(3){public $ static => array(3){   'documentPersister'=>类   Doctrine \ ODM \ MongoDB \ Persisters \ DocumentPersister#166(11){...}   'classMetadata'=>类   Doctrine \ ODM \ MongoDB \ Mapping \ ClassMetadata#155(38){...}   'reflectionId'=> class ReflectionProperty#165(2){...}} public   $ this => class Doctrine \ ODM \ MongoDB \ Proxy \ ProxyFactory#78(7){   private $ metadataFactory =>类   Doctrine \ ODM \ MongoDB \ Mapping \ ClassMetadataFactory#74(9){...}   private $ uow => class Doctrine \ ODM \ MongoDB \ UnitOfWork#76(23){...}   private $ proxyNamespace => string(7)“Proxies”private $ proxyGenerator   => class Doctrine \ Common \ Proxy \ ProxyGenerator#79(4){...} private $ autoGenerate => int(1)private $ definitions =>数组(1){...}   private $ metadataFactory =>类   Doctrine \ ODM \ MongoDB \ Mapping \ ClassMetadataFactory#74(9){...}}   public $ parameter => array(1){'$ proxy'=> string(10)“”}} public   $ isInitialized => bool(false)protected $ _id => NULL保护   $ label => NULL protected $ id => string(24)“54de5341642c8769150041a7”   }

1 个答案:

答案 0 :(得分:0)

我认为问题可能导致使用“simple = true”

  

简单引用减少了文档本身和引用字段上的任何索引所使用的存储量;但是,简单引用不能与鉴别器一起使用,因为没有DBRef对象可以存储鉴别器值。

documetation