2
我无法对嵌入文档进行排序。这是我的代码。使用Doctrine ODM对Symfony2中的嵌入文档进行排序
Children.php
namespace Acme\CCBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class Children {
/..
/**
* @MongoDB\EmbedMany(targetDocument="Vaccine")
*/
protected $vaccine = array();
}
Vaccine.php
namespace Acme\CCBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\EmbeddedDocument
*/
class Vaccine
{
/**
* @MongoDB\Date
*/
protected $recordDate;
/**
* @MongoDB\String
*/
protected $vaccineName;
}
在我的控制器:RecordController.php
public function showVaccineAction($id) {
$child = $this->get('doctrine_mongodb')
->getRepository('AcmeCCBundle:Children')
->find($id);
$vac = $child->getVaccine();
return $this->render(
'AcmeCCBundle:Record:show_vaccine.html.twig', array('vac' => $vac)
);
}
我只能够查询一个孩子的所有疫苗,并没有订购。有谁能够帮助我?