I got this exception “… EntityCategoryProxy could not be converted to int in …” when I wanted to make such loop in my TWIG template:
{% for category in categories %}
{{category.name}}
{% for fund in funds %}
{% if fund.category == category.id %} <<<<<<< EXCEPTION LINE
{{fund.fundName}}
{% endif %}
{% endfor %}
{% endfor %}
WORKING CATEGORY RETRIEVAL (after accepted ANSWER change)
$repository2 = $this->getDoctrine()
->getRepository('ToolsTFIBundle:Category');
$query2 = $repository2->createQueryBuilder('c')
->orderBy('c.name','ASC')
->getQuery();
$categoryList = $query2->getResult();
ALSO WORKING CATEGORY RETRIEVAL (after accepted ANSWER change)
$em = $this->getDoctrine();
$categoryList = $em->getRepository( 'ToolsTFIBundle:Category' )
->findAll();
“fund.category” is foreign key mapped to “category.id” via Doctrine2 ORM. Is there any option to make this loop valid and working?
fund.category is not comparable with category.id because fund.category is an entity.
Use fund.category.id == category.id