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)
);
}
我只能夠查詢一個孩子的所有疫苗,並沒有訂購。有誰能夠幫助我?