2016-11-04 4 views
0

Я пытаюсь создать API для своего приложения, и я хочу включить 3 таблицы в один get.Как сделать многоуровневый API Doctrine

Это, как я получаю сейчас

{ 
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; 
} 

Есть ли простой способ сделать это в учении?

ответ

0
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; 
} 
Смежные вопросы