无法随时获取引用的实体属性,只能在呈现方法中获取


Can't get referenced entity properties anytime, only in rendering method

/** @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(返回

类 Proxies__CG__''教义''文件''实体''实体2#178 (6( { public $initializer => class Closure#160 (3( { public $static => array(2( { 'documentPersister' => class Doctrine''ODM''MongoDB''Persisters''DocumentPersister#166 (11( { ... } 'reflectionId' => class ReflectionProperty#165 (2( { ... } }公共 $this =>类 Doctrine''ODM''MongoDB''Proxy''ProxyFactory#78 (7( { 私人$metadataFactory =>类 Doctrine''ODM''MongoDB''Mapping''ClassMetadataFactory#74 (9( { ... } private $uow => class Doctrine''ODM''MongoDB''UnitOfWork#76 (23( { ... } 私有$proxyNamespace => 字符串(7( "代理"私有$proxyGenerator =>类 Doctrine''Common''Proxy''ProxyGenerator#79 (4( { ... } private $autoGenerate => int(1( private $definitions => array(1( { ... } 私人$metadataFactory =>类 Doctrine''ODM''MongoDB''Mapping''ClassMetadataFactory#74 (9( { ... } } public $parameter => array(1( { '$proxy' => string(10( " } } public $cloner => class Closure#170 (3( { public $static => array(3( { 'documentPersister' =>类 Doctrine''ODM''MongoDB''Persisters''DocumentPersister#166 (11( { ... } '类元数据' =>类 Doctrine''ODM''MongoDB''Mapping''ClassMetadata#155 (38( { ... } 'reflectionId' => class ReflectionProperty#165 (2( { ... } }公共 $this =>类 Doctrine''ODM''MongoDB''Proxy''ProxyFactory#78 (7( { 私人$metadataFactory =>类 Doctrine''ODM''MongoDB''Mapping''ClassMetadataFactory#74 (9( { ... } private $uow => class Doctrine''ODM''MongoDB''UnitOfWork#76 (23( { ... } 私有$proxyNamespace => 字符串(7( "代理"私有$proxyGenerator =>类 Doctrine''Common''Proxy''ProxyGenerator#79 (4( { ... } private $autoGenerate => int(1( private $definitions => array(1( { ... } 私人$metadataFactory =>类 Doctrine''ODM''MongoDB''Mapping''ClassMetadataFactory#74 (9( { ... } } public $parameter => array(1( { '$proxy' => string(10( " } } public $isInitialized => bool(false( protected $_id => NULL 受保护 $label => 空保护 $id => 字符串(24( "54de5341642c8769150041a7" }

我认为这个问题可能会导致使用"simple=true">

简单引用

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

看文档