我有2個表格:jobs
和categories
。第一個表格有一個名爲cat_id
的字段,它是對categories
的引用。 id
。在我的實體類Job
我有註釋是這樣的:原則中的關聯映射
/**
* @ManyToOne(targetEntity="Category")
* @JoinColumn(name="cat_id", referencedColumnName="id")
**/
private $category;
public function __construct()
{
$this->category = new \Doctrine\Common\Collections\ArrayCollection();
}
而在我的類別I類有:
/**
* @OneToMany(targetEntity="Job", mappedBy="job")
* @JoinColumn(name="id", referencedColumnName="cat_id")
*/
private $jobs;
public function __construct()
{
$this->jobs = new \Doctrine\Common\Collections\ArrayCollection();
}
我想要的是按類別得到與他們的類別中的所有作業和所有作業。但我仍然對新學說感到陌生。
你的實體在這裏是正確的,不是嗎?我想你應該通過在EntityRepository中使用查詢構建器來創建自定義請求。 – Debflav