2014-01-25 99 views
0

我有两个实体:以ManyToMany关系链接的项目和课程。ManyToMany关系上的Doctrine2 findBy()

从实体\ Project.php

/** 
* @var Course[] 
* 
* @ORM\ManyToMany(targetEntity="Talentec\SdBundle\Entity\Course", inversedBy="projects") 
*/ 
private $courses; 

提取摘自实体\ Course.php

/** 
* @var Project[] 
* 
* @ORM\ManyToMany(targetEntity="Talentec\SdBundle\Entity\Project", mappedBy="courses") 
*/ 
private $projects; 

在我的控制,我想用教条的findBy()(或findByProject( )),以查找与某个项目相关的所有课程。

是否可以执行以下操作:

$this->getDoctrine()->getRepository('SdBundle:Course')->findBy(array('project' => $projectID)); 

或:

$this->getDoctrine()->getRepository('SdBundle:Course')->findByProject(project_id); 

我不认为这是可能的,原因在于对课程领域被声明为$projects事实(由于ManyToMany关系),而不是$project

有没有类似的方式来查找在ManyToMany关系链接的实体?

回答