title: Render template relation ManyToMany Symfony Doctrine
body: <p>Please help with this, I am having this problem when I render the template twig in the controller, having problems with relations ManyToMany</p>
  
  <p>Neither the property "nombre" nor one of the methods "nombre()", "getnombre()"/"isnombre()" or "__call()" exist and have public access in class "Doctrine\ORM\PersistentCollection"....I will put my entities and controller, please help me with this:</p>
  
  <pre><code>&lt;?php
  
  namespace AdminBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Doctrine\Common\Collections\ArrayCollection;
  
  /**
   * Menu
   *
   * @ORM\Table(name="menu")
   * @ORM\Entity(repositoryClass="AdminBundle\Repository\MenuRepository")
   */
  class Menu
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var float
       * @Assert\NotBlank()
       * @Assert\Type(type="float")
       * @ORM\Column(name="precio", type="float")
       */
      private $precio;
  
      /**
       * @var \DateTime
       * @Assert\Date()
       * @Assert\NotBlank()
       * @ORM\Column(name="fecha", type="date")
       */
      private $fecha;
  
      /**
       * @var \DateTime
       * @Assert\DateTime()
       * @Assert\NotBlank()
       * @ORM\Column(name="fechacomprar", type="datetime")
       */
      private $fechacomprar;
  
  
      /**
       * @var \DateTime
       * @Assert\DateTime()
       * @Assert\NotBlank()
       * @ORM\Column(name="fechavence", type="datetime")
       */
      private $fechavence;
  
      /**
       * @var \Doctrine\Common\Collections\Collection
       *
       * @ORM\ManyToMany(targetEntity="Alimento", inversedBy="menu")
       * @ORM\JoinTable(name="alimento_menu",
       *   joinColumns={
       *     @ORM\JoinColumn(name="menu_id", referencedColumnName="id")
       *   },
       *   inverseJoinColumns={
       *     @ORM\JoinColumn(name="alimento_id", referencedColumnName="id")
       *   }
       * )
       */
      private $alimento;
  
      /**
       * Constructor
       */
      public function __construct()
      {
          $this-&gt;alimento = new ArrayCollection();
      }
  
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set precio
       *
       * @param float $precio
       *
       * @return Menu
       */
      public function setPrecio($precio)
      {
          $this-&gt;precio = $precio;
  
          return $this;
      }
  
      /**
       * Get precio
       *
       * @return float
       */
      public function getPrecio()
      {
          return $this-&gt;precio;
      }
  
      /**
       * Set fecha
       *
       * @param \DateTime $fecha
       *
       * @return Menu
       */
      public function setFecha($fecha)
      {
          $this-&gt;fecha = $fecha;
  
          return $this;
      }
  
      /**
       * Get fecha
       *
       * @return \DateTime
       */
      public function getFecha()
      {
          return $this-&gt;fecha;
      }
  
      /**
       * Set fechacomprar
       *
       * @param \DateTime $fechacomprar
       *
       * @return Menu
       */
      public function setFechacomprar($fechacomprar)
      {
          $this-&gt;fechacomprar = $fechacomprar;
  
          return $this;
      }
  
      /**
       * Get fechacomprar
       *
       * @return \DateTime
       */
      public function getFechacomprar()
      {
          return $this-&gt;fechacomprar;
      }
  
      /**
       * Set fechavence
       *
       * @param \DateTime $fechavence
       *
       * @return Menu
       */
      public function setFechavence($fechavence)
      {
          $this-&gt;fechavence = $fechavence;
  
          return $this;
      }
  
      /**
       * Get fechavence
       *
       * @return \DateTime
       */
      public function getFechavence()
      {
          return $this-&gt;fechavence;
      }
  
  
      /**
       * Add alimento
       *
       * @param \AdminBundle\Entity\Alimento $alimento
       *
       * @return Menu
       */
      public function addAlimento(Alimento $alimento)
      {
          $this-&gt;alimento[] = $alimento;
  
          return $this;
      }
  
      /**
       * Remove alimento
       *
       * @param \AdminBundle\Entity\Alimento $alimento
       */
      public function removeAlimento(Alimento $alimento)
      {
          $this-&gt;alimento-&gt;removeElement($alimento);
      }
  
      /**
       * Get alimento
       *
       * @return \Doctrine\Common\Collections\Collection
       */
      public function getAlimento()
      {
          return $this-&gt;alimento;
      }
  }
  
  
  &lt;?php
  
  namespace AdminBundle\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;
  
  
  /**
   * Alimento
   *
   * @ORM\Table(name="alimento")
   * @ORM\Entity(repositoryClass="AdminBundle\Repository\AlimentoRepository")
   * @DoctrineAssert\UniqueEntity("nombre")
   */
  class Alimento
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       * @Assert\NotBlank(message="Debe escribir un alimento")
       * @Assert\Type(type="string")
       * @Assert\Regex(pattern="/\d/", match=false, message="Debe escribir un nombre válido")
       * @ORM\Column(name="nombre", type="string", length=255, unique=true)
       */
      private $nombre;
  
      /**
       * @var float
       * @Assert\NotBlank(message="Debe especificar un precio")
       * @Assert\Type(type="float", message="Debe escribir un precio válido")
       * @ORM\Column(name="precio", type="float")
       */
      private $precio;
  
  
      /**
       * @ORM\ManyToOne(targetEntity="TipoAlimento")
       * @Assert\NotBlank()
       */
      private $tipo;
  
      /**
       * @var \Doctrine\Common\Collections\Collection
       *
       * @ORM\ManyToMany(targetEntity="Menu", mappedBy="alimento")
       */
      private $menu;
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set nombre
       *
       * @param string $nombre
       *
       * @return Alimento
       */
      public function setNombre($nombre)
      {
          $this-&gt;nombre = $nombre;
  
          return $this;
      }
  
      /**
       * Get nombre
       *
       * @return string
       */
      public function getNombre()
      {
          return $this-&gt;nombre;
      }
  
      /**
       * Set precio
       *
       * @param float $precio
       *
       * @return Alimento
       */
      public function setPrecio($precio)
      {
          $this-&gt;precio = $precio;
  
          return $this;
      }
  
      /**
       * Get precio
       *
       * @return float
       */
      public function getPrecio()
      {
          return $this-&gt;precio;
      }
  
      /**
       * Set tipo
       *
       * @param \AdminBundle\Entity\TipoAlimento $tipo
       *
       * @return Alimento
       */
      public function setTipo(TipoAlimento $tipo)
      {
          $this-&gt;tipo = $tipo;
  
          return $this;
      }
  
      /**
       * Get tipo
       *
       * @return \AdminBundle\Entity\TipoAlimento
       */
      public function getTipo()
      {
          return $this-&gt;tipo;
      }
  
      /**
       * @return string
       */
      function __toString()
      {
          return $this-&gt;getNombre();
      }
  
      /**
       * Constructor
       */
      public function __construct()
      {
          $this-&gt;menu = new ArrayCollection();
      }
  
      /**
       * Add menu
       *
       * @param \AdminBundle\Entity\Menu $menu
       *
       * @return Alimento
       */
      public function addMenu(Menu $menu)
      {
          $this-&gt;menu[] = $menu;
  
          return $this;
      }
  
      /**
       * Remove menu
       *
       * @param \AdminBundle\Entity\Menu $menu
       */
      public function removeMenu(Menu $menu)
      {
          $this-&gt;menu-&gt;removeElement($menu);
      }
  
      /**
       * Get menu
       *
       * @return \Doctrine\Common\Collections\Collection
       */
      public function getMenu()
      {
          return $this-&gt;menu;
      }
  }
  </code></pre>
  
  <p>The controller:</p>
  
  <pre><code>    public function indexAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $menu = $em-&gt;getRepository('AdminBundle:Menu')-&gt;findAll();
          return $this-&gt;render('AdminBundle:menu:index.html.twig', array(
              'menu' =&gt; $menu,
          ));`enter code here`
      }
  </code></pre>
  
  <p>And in the template I am doing the things like this:</p>
  
  <pre><code> {% for m in menu %}
                      &lt;tr&gt;
                          &lt;td&gt;{{ m.id }}&lt;/td&gt;
                          &lt;td&gt;{{ m.fecha | date('d/m/y') }}&lt;/td&gt;
                          &lt;td&gt;{{ m.alimento.nombre }}&lt;/td&gt;
                          &lt;td&gt;{{ m.fechacomprar | date('d/m/y') }}&lt;/td&gt;
                          &lt;td&gt;{{ m.fechavence | date('d/m/y') }}&lt;/td&gt;
                          &lt;td&gt;{{ m.precio }}&lt;/td&gt;
                      &lt;/tr&gt;
                  {% endfor %}
  </code></pre>
  
  <p>Problem here is m.alimento.nombre is wrong!</p>