如何制作Doctrine多级API



我正在尝试为我的应用程序做一个API,我想在一个get中包含3个表。

这是我现在得到它的方式

{
id: 1,
tocht_id: 1,
user_id: 1,
started_bool: true,
finished_bool: false
},

我想得到这样的数据

{
id: 1,
tocht   {
    id: 1
    naam: intro tocht
    opleiding: testOpleiding
    informatie: testInfo }
user    {
    id: 1
    naam: vincent
    pin: 666 }
started_bool: true,
finished_bool: false
},
这是我获取数据的代码
public function getAction()
    {
      $restresult = $this->getDoctrine()->getRepository('AppBundle:Koppel_tocht_user')->findAll();
        if ($restresult === null) 
        {
          return new View("there are no records to display.", Response::HTTP_NOT_FOUND);
        }
    return $restresult;
}

在理论中是否有简单的方法来做到这一点?

public function getAction()
{
  $restresult = $this->getDoctrine()->getRepository('AppBundle:Koppel_tocht_user')->findAll();
  //var_dump($restresult);
  foreach ($restresult as $value) {
    $questId = $value->getTochtId();
    $userId = $value->getUserId();
    $questResult = $this->getDoctrine()->getRepository('AppBundle:Speurtocht')->findById($questId);
    $userResult = $this->getDoctrine()->getRepository('AppBundle:User')->findById($userId);
    $value->setQuest($questResult);
    $value->setUser($userResult);
  }
    if ($restresult === null) 
    {
      return new View("there are no records to display.", Response::HTTP_NOT_FOUND);
    }
    return $restresult;
}