doctrine2 - doctrine: is there a way to use associated entity in findBy -
i have entity 'employee' associated 1 or more 'manager' entities. therefore use join table , association in employee entity follows:
/** * @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;
this working. want retrieve employees of specific manager. therefore i'm asking if possible this:
$mgr = $this->em->getrepository ( 'entities\manager' )->findoneby ( array ( "alias" => $this->get('alias')); // pseudo code - know $managers list of managers , $mgr cannot compared $emplist = $this->em->getrepository('entities\employee')->findby(array("managers" => $mgr));
add function repository:
public function findbymanager($managerid) { return $this->getentitymanager() ->createquerybuilder() ->from('employee', 'e') ->innerjoin('e.managers m') ->where('m.id = :managerid') ->setparameter('managerid', $managerid) ->getquery() ->getresult(); }
and use:
$employee = $repository->findbymanager($manager->getid());
Comments
Post a Comment