2012-08-01 90 views
0

我有一些问题与主义MongoDB的ODM和Symfony的2主义的MongoDB - 对文档的查询与嵌入文档的多级

嵌入文档要揭露问题,我有记录产品embedOne productInformation和productInformation embedOne productInformationAddress。

要查询,我用类似的东西:

/** 
* @ODM\Document 
**/ 
class product { 
    /** 
    * @ODM\EmbedOne(targetDocument="productInformation") 
    **/ 
    protected $informations; 
} 

/** 
* @ODM\EmbeddedDocument 
**/ 
class productInformations { 
    /** 
    * @ODM\EmbedOne(targetDocument="productInformationAddress") 
    **/ 
    protected $address; 

    /** 
    * @ODM\Collection 
    **/ 
    protected $attr1 = array(); 

    /** 
    * @ODM\String 
    **/ 
    protected $attr2 
} 

/** 
* @ODM\EmbeddedDocument 
**/ 
class productInformationAddress { 
    /** ... suff ... /* 
} 

当我查询:

class productRepository { 
    public function fetchOne($id) { 
     return $this->createQueryBuilder() 
      ->field('id')->equals($id) 
      ->getQuery() 
      ->getSingleResult(); 
    } 
} 

但是,我不明白为什么我不能得到$product->getInformations()->getAddress(),总是返回null .. 。

有什么想法?

回答

0

我没有看到您发布的代码存在问题,但它可能有助于通过ODM的嵌套,嵌入式文档的功能测试。在EmbeddedTest.php中,感兴趣的方法可以是使用EmbeddedTestLevel2的任何东西,这相当于productInformationAddress类和testRemoveAddDeepEmbedded()

+0

谢谢你的回答,事实上,问题很简单......缓存...但是,你是对的,并感谢你的测试链接。 – Spike008t 2012-08-06 15:09:37