我有一个实体“员工”,它与一个或多个“经理”实体相关联。因此,我在员工实体中使用连接表和关联,如下所示:
/**
* @ManyToMany(targetEntity="manager_entity")
* @JoinTable(name="manager_employees",
* joinColumns={@JoinColumn(name="emp_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="manager_id", referencedColumnName="id", unique=true)}
* )
*/
protected $managers;
这已经在起作用了。但现在我想检索特定经理的所有员工。因此我问是否有可能做这样的事情:
$mgr = $this->em->getRepository ( 'Entities\manager' )->findOneBy ( array (
"alias" => $this->get('alias'));
// only pseudo code - i know that $managers is a list of managers and $mgr cannot be compared to that
$empList = $this->em->getRepository('Entities\employee')->findBy(array("managers" => $mgr));