Hi,
Disclaimer: I am also learning Mongo with PHP, so everything here could be completely wrong. LOL!.;)
It seems you are using Doctrine's MongoDB ODM, correct? If so, you could just use the methods (like get and set) from the ODM itself, right?
/**
* @MongoDB\Document
*/
class Test
{
/**
* @MongoDB\Id
*/
private $id;
/**
* @MongoDB\Collection
*/
private $foo = array();
/** @MongoDB\ReferenceMany(targetDocument="Prova") */
private $prova = array(); }
/**
* @MongoDB\Document
*/
class Prova
{
/**
* @MongoDB\Id
*/
private $id;
/**
* @MongoDB\string
*/
private $message;
/**
* @MongoDB\string
*/
private $city;
}
public function getAction($dm, $id)
{ $qb = $dm->createQueryBuilder('Test') ->field('prova')->prime(true) ->findOneBy(array('id'=>$id); //prime(true) = get references in one additional db query.
$query = $qb->getQuery();
$test = $query->execute();
if (!$test) {
return $this->render('AcmeProvaBundle:Default:prova.html.twig');
}
foreach ($test->getProvas() as $prova) {
//your code here to manipulate $pro ???
}
// or if you only want the object.
$pro = $test->getProvas();
return $this->render('AcmeProvaBundle:Default:prova.html.twig', array('test' => $test, 'pro' => $pro));
}
http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/priming-references.html
Notice I also changed the class name Prove to Prova. I am not sure if that is really needed, but I think for naming conventions within Doctrine ODM, it seems better/ simpler.
Again, I am just learning too, so this could all be wrong.:)
Scott