我有以下两个类,它们具有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;
}
该关系在 YML 中定义如下
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