0

I have two Documents: Client and PV. Many PV are referenced in one Client. It's unidirectional.

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();
    }
}

PV

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

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

To fetch a Client Document I use:

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

And I get:

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

But I want:

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

So how can I fetch just the Parent Document with MongoIds for every PV referenced not the entires referenced PVs ? (In MongoDB when I do db.Client.find({name: 'Test'}) I got the MongoIds not the documents). Is it related to the Doctrine MongoDB hydrator ?

RChanaud
  • 194
  • 2
  • 12
  • hmn it should just return $MongoId of referenced PV, and you lazy load it with $client->getPV() – john Smith Jul 04 '14 at 15:00
  • Thanks for your comment John. But I can't figure out why `return $client->getPV()` fetches all the PVs and not the $MongoIds of them. It's not lazyloaded, it's completely loaded. – RChanaud Jul 07 '14 at 16:05

0 Answers0