I'm using Silex with Doctrine ORM trying to create mappings to the database with YAML. I have a many to many relationship between the categories
and products
tables and wish to have categories on the owner side.
However, whenever I try to dump '$productCategories' in the twig file by
{% for productCategories in category.productCategories %}
<li><a href=""></a>{{ productCategories.name }}</li>
{% endfor %}
I receive:
Variable "productCategories" does not exist in "category.twig"
Here is the Categories.yml file:
MVCStore\Entity\Category:
type: entity
table: categories
manyToMany:
productCategories:
targetEntity: MVCStore\Entity\Product
inversedBy: category
joinTable:
name: products_categories
joinColumns:
products:
referencedColumnName: id
inverseJoinColumns:
categories:
referencedColumnName: id
id:
id:
type: integer
generator:
strategy: auto
fields:
name:
type: string
parent_id:
type: integer
And here is the products.yml file:
MVCStore\Entity\Product:
type: entity
table: products
repositoryClass: MVCStore\EntityRepository\Product
oneToMany:
productImages:
targetEntity: MVCStore\Entity\ProductImage
mappedBy: product
manyToMany:
productCategories:
targetEntity: MVCStore\Entity\Category
mappedBy: products
id:
id:
type: integer
generator:
strategy: auto
fields:
stock:
type: integer
name:
type: string
description:
type: string
featured:
type: boolean
price:
type: decimal
If anything more is needed please ask.