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%}
<tr>
<td>{{ adverts.id }}</td>
<td>{{ adverts.name }}</td>
<td>{{ adverts.users }}</td>
<td>
{% for category in adverts.categories %}
{{ adverts.categories }}
{% endfor %}
</td>
<td>
<a href="{{ path('editAdverts', {'name': adverts.name}) }}"><button class="btn btn-warning btn-xs">Edit</button></a>
</td>
</tr>
{% endfor %}
WHERE a.categories = c.id
This line should cause the error. I think in your case, you should use a.categories.id instead of a.categories.
You can't equalize an object with an integer.