我有一個多對多關係,當我加載一個這個關係的一邊的實體時,我期望看到它的屬性另一側的相關實體的ArrayCollection。然而,這不會發生 - ArrayCollection加載沒有元素,而在數據庫中,我可以看到相關的條目。可能是什麼原因?Symfony2:學說不會加載多對多關係的相關實體
這裏是我的代碼:關係的
一面,ConsolidatedReport類:
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="P24\Response", inversedBy="consolidatedReports")
* @ORM\JoinTable(name="con_rprt_responses")
*/
private $responses;
關係的另一面,Response類:
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="P24\ConsolidatedReport\ConsolidatedReport", mappedBy="responses")
*/
private $consolidatedReports;
這是我跑的功能獲取ConsolidatedReport的一個實例。該功能位於一個正在被從容器調用服務中:
/**
* Picks the consolidated report with given id.
*
* @param string $id
*
* @return ConsolidatedReport
*
* @throws NonExistentConsolidatedReportException if the survey doesn't exist
*/
public function pick($id)
{
$report = $this->repository->findOneBy(array('id' => $id));
if (!$report) {
throw new NonExistentConsolidatedReportException($id);
}
return $report;
}'
在數據庫中,有「con_rprt_responses」表有兩列「consolidated_reports_id」和「RESPONSE_ID」。但是,在剖析器中,我沒有看到該表的任何查詢。
這裏可能會出現什麼問題?
更新: 請看我對下面這個問題的回答,那對我有用。
在分析器中,我看不到任何對「con_rpt_responses」表的查詢。 – Vasily802