我在使用 Doctrine MongoDB ODM 和 Symfony 2 嵌入文档时遇到了一些问题。
为了暴露这个问题,我有文档 product 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......
任何想法?