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关系链接的实体?
死链接,所以这个答案现在已经过时。 – Alec
@Alec我更新了链接 –