in order to know how it really works, there is an unanswered question from Stack website, and notice that I have the similar problem.
In my SQl database, I
You shouldn't use DQL or others direct queries in your controllers if not really necessary. You should do this:
public function indexAdvertsAction() {
$em=$this->getDoctrine()->getManager();
$adverts = $em->getRepository('MySpaceMyBundle:Adverts')->findAll();
return $this->render(
'MySpaceMyBundle:MyFolder:indexAdverts.html.twig',
array('adverts' => $adverts )
);
}
Then, in your template, the advert entity will take care of the rest, thanks to the correct relations mapping:
{% for adverts in advert%}
{{ adverts.id }}
{{ adverts.name }}
{{ adverts.users }}
{% for category in adverts.categories %}
{{ adverts.categories }}
{% endfor %}
{% endfor %}