简体   繁体   English

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

[英]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;
}

My problem is when I call referenced entity $entity->getEntity2() it returns the entity2 but with public $__isInitialized__ => bool(false) . 我的问题是,当我调用引用的实体$entity->getEntity2()它返回entity2但是使用public $__isInitialized__ => bool(false) Then when I try to call $entity->getEntity2()->getId() it throws Doctrine\\ODM\\MongoDB\\DocumentNotFoundException The "Proxies\\__CG__\\Doctrine\\Documents\\Entities\\Entity2" document with identifier "54de5341642c8769150041a7" could not be found. 然后,当我尝试调用$entity->getEntity2()->getId()它会抛出Doctrine\\ODM\\MongoDB\\DocumentNotFoundException The "Proxies\\__CG__\\Doctrine\\Documents\\Entities\\Entity2" document with identifier "54de5341642c8769150041a7" could not be found.

Weird is that this happen when I call it before rendering in my framework. 奇怪的是,当我在我的框架中渲染之前调用它时会发生这种情况。 When I do the same during rendering method it works but it doesn't work for example in form submit-handling methods... 当我在渲染方法中执行相同操作时,它可以工作,但它不能用于表单提交处理方法...

I have cleaned cache, proxies and hydrators. 我已经清理了缓存,代理和水合物。 The document with this ObjectID is in my database and it gets returned, only not initialized and can't get any of its properties except in the rendering method 具有此ObjectID的文档位于我的数据库中,它将被返回,只是没有初始化,除了渲染方法之外无法获取任何属性

This is returned by calling getEntity2() (mind $__isInititalized = false ) 这是通过调用getEntity2()返回的(介意$__isInititalized = false

class Proxies__CG__\\Doctrine\\Documents\\Entities\\Entity2#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) { ... } } public $this => class Doctrine\\ODM\\MongoDB\\Proxy\\ProxyFactory#78 (7) { private $metadataFactory => class 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 => array(1) { ... } private $metadataFactory => class 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' class Proxies__CG __ \\ Doctrine \\ Documents \\ Entities \\ Entity2#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){...}} public $ this => class Doctrine \\ ODM \\ MongoDB \\ Proxy \\ ProxyFactory#78( 7){private $ metadataFactory => class 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 => array(1){...} private $ metadataFactory => class 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' => class Doctrine\\ODM\\MongoDB\\Persisters\\DocumentPersister#166 (11) { ... } 'classMetadata' => class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata#155 (38) { ... } 'reflectionId' => class ReflectionProperty#165 (2) { ... } } public $this => class Doctrine\\ODM\\MongoDB\\Proxy\\ProxyFactory#78 (7) { private $metadataFactory => class 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 => array(1) { ... } private $metadataFactory => class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadataFactory#74 (9) { ... } } public $parameter => array(1) { '$proxy' => string(10) "" } } public $ isInitialized => bool(false) protected $_id => NULL protected $label => NULL protected $id => string(24) "54de5341642c8769150041a7" } => class Doctrine \\ ODM \\ MongoDB \\ Persisters \\ DocumentPersister#166(11){...}'classMetadata'=> class Doctrine \\ ODM \\ MongoDB \\ Mapping \\ ClassMetadata#155(38){...}'reflectionId' => class ReflectionProperty#165(2){...}} public $ this => class Doctrine \\ ODM \\ MongoDB \\ Proxy \\ ProxyFactory#78(7){private $ metadataFactory => class 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 => array(1){...} private $ metadataFactory => class Doctrine \\ ODM \\ MongoDB \\ Mapping \\ ClassMetadataFactory#74(9){...}} public $ parameter => array(1){'$ proxy'=> string(10)“”}} public $ isInitialized => bool(false )protected $ _id => NULL protected $ label => NULL protected $ id => string(24)“54de5341642c8769150041a7”}

I think the problem may cause the use of "simple=true" 我认为问题可能导致使用“simple = true”

Simple references reduce the amount of storage used, both for the document itself and any indexes on the reference field; 简单引用减少了文档本身和引用字段上的任何索引所使用的存储量; however, simple references cannot be used with discriminators, since there is no DBRef object in which to store a discriminator value. 但是,简单引用不能与鉴别器一起使用,因为没有DBRef对象存储鉴别器值。

look documetation 看看文件

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

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