【发布时间】:2017-05-09 20:20:03
【问题描述】:
我需要为我们的预订存储一些数据,其中包括客户数据,我希望将其作为预订文档中的嵌入文档。使用我当前的配置,所有数据都保存在 MongoDB 中,但是当我加载预订文档时,没有相关的客户对象。我是否忘记了某些配置或其他内容?
这是我的文档的样子:
预订文件:
<?php
namespace AppBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class Booking
{
/**
* @MongoDB\EmbedOne(targetDocument="\AppBundle\Document\Customer")
*/
private $customer;
// getter and setter...
}
客户文档
<?php
namespace AppBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\EmbeddedDocument
*/
class Customer
{
// fields, getter and setter
}
【问题讨论】:
-
改用
@MongoDB\EmbedOne(targetDocument="Customer")。 -
执行
CTRL+F并查找mongohere 以获得 symfony+mongodb 示例。例如Simple doctrine mongodb example for EmbedOne in symfony
标签: php symfony doctrine doctrine-odm odm