Studyng symfony.. I have two entities like this
Articoli entity
/**
* @ORM\Entity(repositoryClass="App\Repository\ArticoliRepository")
*/
class Articoli
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $nome;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Categorie", inversedBy="articoli")
* @ORM\JoinColumn(nullable=false)
*/
private $categoria;
Categorie.php
/**
* @ORM\Entity(repositoryClass="App\Repository\CategorieRepository")
*/
class Categorie
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $categoria;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Articoli", mappedBy="categoria", orphanRemoval=true)
*/
private $articoli;
/**
* @ORM\Column(type="string", length=255)
*/
private $nome;
On indexController i have
$articolo = $this->getDoctrine()->getRepository(Articoli::class)->find(201);
why $articolo categoria.categoria and categoria.articoli are null?? It should be the name of categoria
App\Entity\Articoli {#755 ▼
-id: 201
-nome: "Articolo #1"
-categoria: Proxies\__CG__\App\Entity\Categorie {#742 ▼
+__isInitialized__: false
-id: 29
-categoria: null
-articoli: null
…2
}
}
Inspecting the profiler the executed query is
SELECT t0.id AS id_1, t0.nome AS nome_2, t0.categoria_id AS categoria_id_3 FROM articoli t0 WHERE t0.id = 201;
Should it be a join no?
thanks