I am using Doctrine2 (Symfony2)
, in my controller I used one repository for one table (MySQL) and it does work. I want to add one repository more and find a record where one field is equal to a field from first (previous) table. Something like:
SELECT * FROM table2 where 'table2.columnX' = 'table1.columnX';
$em = $this->getDoctrine()->getManager();
$employee = $em->getRepository('SomethingBundle:Employee')->find($id); [table1 -- it works!]
how here:
$repository2 = $this->getDoctrine()
->getRepository('NenadStoreBundle:Requirements');
$requirements = $repository2->findById *----where columnX = employeecolumnx
I don't think it is possible to do it this way. Use query builder http://docs.doctrine-project.org/en/2.0.x/reference/query-builder.html
With findBy(array $criteria)
, if you already know the "employeecolumnx" value, you can do what you need.
$em = $this->getDoctrine()->getManager();
$employee = $em->getRepository('SomethingBundle:Employee')->find($id);
$requirements = $em->getRepository('NenadStoreBundle:Requirements')->findBy(
array(
'RequirementColumnX' => $employee->getEmployeeColumnX()
)
);
Change $employee->getEmployeeColumnX()
with the real method name you need to use.