4
我有以下兩個類別,它們具有ManyToMany關係並保存在名爲countries_involved
的連接表中。在原則中查詢加入表格
class CountriesInvolved
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $description;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var \DateTime
*/
private $updatedAt;
/**
* @var \ACME\SouthBundle\Entity\Country
*/
private $country;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $involvement;
}
和
class Involvement
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $description;
}
的關係是陽明
manyToMany:
involvement:
targetEntity: Involvement
joinTable:
name: countries_involvement
joinColumns:
case_country_involved_id:
referencedColumnName: id
inverseJoinColumns:
involvement_id:
referencedColumnName: id
我試圖返回基於一個參與的ID,但那種參與國家的結果定義如下停留在寫入查詢而沒有出現錯誤。以下是我試過到目前爲止:
$em = $this->getDoctrine()->getManager()->createQueryBuilder();
$q = $em->select('c')
->from('ACMESouthBundle:CountriesInvolved','c')
->innerJOIN('c.Involvement','i')
->where('i.id = 1')
->groupBy('c.country')->getQuery();
的錯誤是:
[Semantical Error] line 0, col 80 near 'i WHERE i.id': Error: Class ACME\SouthBundle\Entity\CountriesInvolved has no association named Involvement
對不起我,而不是使用註釋YML但您的解決方案工作就像一個魅力。我想知道我哪裏錯了,因爲我有同樣的事情,但有涉及CountriesInvolved的關係 –
我剛剛更新了答案。注意'inversedBy'和'MappedBy'語句。希望這可以幫助 ;)。 – 2013-10-21 11:45:13