我在institute
和"课程"之间有很多对很多的关系。
class Institutes {
/**
* @ORMManyToMany(targetEntity="PNCCoursesBundleEntityCourses", inversedBy="institutes")
* @ORMJoinTable(name="institute_courses",
* joinColumns={@ORMJoinColumn(name="institute_id", referencedColumnName="id")},
* inverseJoinColumns={@ORMJoinColumn(name="course_id", referencedColumnName="id")}
* )
*/
protected $courses;
}
class Courses {
/**
* @ORMManyToMany(targetEntity="PNCInstitutesBundleEntityInstitutes", mappedBy="courses")
*/
protected $institutes;
}
我制作了一张表格,在onece为一所学院分配多门课程,效果很好。现在我想通过条令查询获得分配给学院的课程列表,我有下面的查询,但id不起作用。
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('PNCInstitutesBundle:Institutes');
$query = $repository->createQueryBuilder('i')
->innerJoin('i.courses', 'g')
->where('i.id = :inst_id')
->setParameter('inst_id',3)
->getQuery()->getResult();
$repository = $em->getRepository('PNCCoursesBundle:Courses');
$courses = $repository->createQueryBuilder('i')
->innerJoin('i.institutes', 'g')
->where('g.id = :inst_id')
->setParameter('inst_id',$instituteID)
->getQuery()->getResult();