假设你已经配置了实体之间的一对多的关系,就像这样:
产品实体:
/**
* @ORM\OneToMany(targetEntity="Aplication", mappedBy="product", cascade={"persist"})
*/
protected $aplications;
Aplication实体:
* @ORM\ManyToOne(targetEntity="Product", inversedBy="aplications")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="product_id", referencedColumnName="id")
* })
protected $product;
你可以在你的产品仓库上创建一个这样的DQL:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('p')
->from('bundleNamespace:Product', 'p')
->leftJoin('p.applications', 'a')
->andWhere($qb->expr()->in('a.id', ':aplication'))
->setParameter('aplication', $aplication);
return $qb->getQuery()->getResult();
你需要使用DQL。 – mpm 2013-04-11 11:10:11
而你必须创建一个新的实体调用应用程序。然后以OneToMany关系加入产品和应用程序。 在此之后,您可以使用Doctrine的DQL进行自定义请求 – Pierrickouw 2013-04-11 13:21:35