2016-11-04 2 views
0

내 앱용 API를 만들려고하고 있는데 하나의 테이블에 3 개의 테이블을 포함하고 싶습니다.Doctrine 다중 레벨 API를 만드는 방법

이 내가이

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

가있는 데이터를 얻을 내 코드이

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

같은 데이터를 얻으려면 지금

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

그것을 얻는 방법이다 교리에서 이것을 쉽게 할 수있는 방법?

답변

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