0

I have these entities

/** @ORM\Entity */
class Produto {

    /* Other attributes */

    /** 
     * @ORM\ManyToOne(targetEntity="Produto\Entity\Categoria")
     * @ORM\JoinColumn(name="categoria_id", referencedColumnName="id")
     */
    private $categoria;

    public function getCategoria() {
        return $this->categoria;
    }

    public function setCategoria(Categoria $categoria) {
        $this->categoria = $categoria;
    }
}

and

/** @ORM\Entity */
class Categoria {

/* Other attributes */

    /** @ORM\Column(type="string") */
    private $nome;

}

but when I call the method findAll the $categoria attribute category is always null, what am I doing wrong?

I tried adding the OneToMany annotation on the entity categoria, but it did not work well, there is somewhere that explains why this happens? I found nothing in the documentation

Wilt
  • 41,477
  • 12
  • 152
  • 203

1 Answers1

0

Class Categoria needs to have an $id class variable. Also, the data in the database for Producto entity needs to have the categoria_id field mapped to the Categoria id for this to work.

Pradeep
  • 2,469
  • 1
  • 18
  • 27