简体   繁体   中英

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) . 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.

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

This is returned by calling getEntity2() (mind $__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 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 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.

look documetation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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