Я пытаюсь получить объекты Ответить с объектом Thread.
Thread.php
class Thread
{
/**
* One thread can have many replies. This is the inverse side.
* @ORM\OneToMany(targetEntity="Reply", mappedBy="thread")
*/
private $replies;
public function __construct()
{
$this->replies = new ArrayCollection();
}
/**
* @return Collection|Reply[]
*/
public function getReplies(): Collection
{
return $this->replies;
}
}
Reply.php
class Reply
{
/**
* @ORM\Column(type="integer")
*/
private $thread_id;
/**
* Many replies have one thread. This is the owning side.
* @ORM\ManyToOne(targetEntity="Thread", inversedBy="replies", fetch="EAGER")
* @ORM\JoinColumn(name="thread_id", referencedColumnName="id")
*/
private $thread;
ThreadController.php
class ThreadController extends Controller
{
/**
* @Route("/thread/{id}")
*/
public function read($id)
{
$thread = $this->getDoctrine()->getRepository(Thread::class)->find($id);
dump($thread); // or dump($thread->getReplies());
}
}
Но по какой-то причине это не работает.ArrayCollection внутри объекта Thread пуст и #initialized: false.Не имеет значения, являются ли свойства частными или общедоступными.
Запрос Doctrine от Symfony Profiler, в нем нет JOIN:
SELECT
t0.id AS id_1,
t0.user_id AS user_id_2,
t0.title AS title_3,
t0.body AS body_4,
t0.created_at AS created_at_5,
t0.updated_at AS updated_at_6
FROM
thread t0
WHERE
t0.id = ?
Где может быть проблема?Спасибо