簡體   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;
}

我的問題是,當我調用引用的實體$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 $ 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”}

我認為問題可能導致使用“simple = true”

簡單引用減少了文檔本身和引用字段上的任何索引所使用的存儲量; 但是,簡單引用不能與鑒別器一起使用,因為沒有DBRef對象存儲鑒別器值。

看看文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM