0

我有两个文件:ClientPV。许多PV在一个Client中引用。它是单向的。

客户

/**
 * @MongoDB\Document
 */
class Client
{
    /**
     * @MongoDB\Id(strategy="auto")
     */
    protected $id;

    /**
     * @MongoDB\String
     */
    protected $name;

    /**
     * @MongoDB\ReferenceMany(targetDocument="PV", simple=true, cascade={"persist", "remove"})
     */
    private $PV = array();

    public function __construct()
    {
        $this->PV = new \Doctrine\Common\Collections\ArrayCollection();
    }
}

光伏

/**
 * @MongoDB\Document
 */
class PV
{
    /**
     * @MongoDB\Id(strategy="auto")
     */
    protected $id;

    /**
     * @MongoDB\String
     */
    protected $name;
}

要获取我使用的客户文档:

$client = $this->get('doctrine_mongodb')
->getRepository('HubMainBundle:Client')
->findOneById($id);

我得到:

"53da113176a2955c6d8b4567": {
    "id": "53da113176a2955c6d8b4567",
    "name": "Test",
    "_p_v": [
        {
            "id": "53da121276a2956c708b4568",
            "name": "test pv"
        },
        {
            "id": "53da4e2876a295b7088b4567",
            "name": "pv 2"
        }
    ]
}

但我想要:

"53da113176a2955c6d8b4567": {
    "id": "53da113176a2955c6d8b4567",
    "name": "Test",
    "_p_v" : [ 
        "53da121276a2956c708b4568", 
        "53da4e2876a295b7088b4567"
    ]
}

那么我如何才能为每个引用的 PV 而不是整个引用的 PV 只获取带有 MongoIds 的父文档?(在 MongoDB 中,db.Client.find({name: 'Test'})我得到的是 MongoIds 而不是文档)。它与 Doctrine MongoDB hydrator 有关吗?

4

0 回答 0