I\'m triyng to understand how the many to many relationship works with Doctrine and Symfony2.
I\'ve recreated the example shown in the official documentation (goo.gl
You can write a join DQL query as below
$em = $this->getContainer()->get('doctrine')->getManager();
$repository = $em->getRepository('YourNamespaceYourBundle:User');
$query = $repository->createQueryBuilder('u')
->innerJoin('u.groups', 'g')
->where('g.id = :group_id')
->setParameter('group_id', 5)
->getQuery()->getResult();
Your mapping for groups
property in User
entity will handle join part itself you don't have to mention the junction table in your DQL query