Mason Mason - 1 year ago 93
PHP Question

How to make a join query on Symfony with Doctrine?

I'm kinda stuck on using the querybuilder to create a join query.
There is a table called "Person" and a table called "Vacancy". If a person is linked to the vacancy the and is saved in a table called "Candidacy". So how do I get all the persons who are linke to 1?

So where do I have to initiate the AppBundle:Candidacy entity?

$entity = $em
->join('', 'c')
->where('c.vacancyId= 1')

Thank you in advance.

Answer Source

Example in your repository :

public function getPersonVacancy($personId) {
    $qb = $this->createQueryBuilder('p');
    $qb->leftJoin('p.vacancy', 'v');
    $qb->select('', '');
    $qb->where(' = :personId');
    $qb->setParameter('personId', $personId);
    return  $qb ->getQuery()->getResult();

This is to give you an example it may not work with copy paste. Also, all join methods are explained in doctrine documentation, feel free to read it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download