2014-01-27 2 views
0

어쩌면 나는 이것을 바보로 삼을 것이다. 그러나 propel로 내 데이터베이스에서 많은 결과를 얻고 싶다.Propel many-to-many join

저는 Acl_Customer, Acl_Group 및 Acl_Customer_Group 테이블을 보유하고 있습니다. 마지막은 고객과 그룹 간의 상호 참조입니다.

이제 그룹 테이블에 조인하여 내 acl 고객을 가져오고 싶을뿐입니다.

 $customers = CustomerQuery::create() 
     ->joinCustomerGroup() 
     ->paginate($page, $limit); 

    return $customers->getResults()->getData(); 

이 다음 날 제공 :

[{"id":1,"username":"foo","email":"[email protected]","groups":[{"name":"developer"}, ...]}] 

누구나 아이디어를 가지고 :

[{"id":1,"username":"foo","email":"[email protected]"}] 

그러나 나는 이런 식으로 뭔가를해야합니까?

답변

1

SQL에서 n 대 n 관계에 "조인"할 수 없습니다. 추가 쿼리를 실행해야 함을 의미합니다.

$result = []; 
foreach ($customers->getResults() as $item) { 
    $result[] = array_merge(
     $item->toArray(), 
     ['groups' => $item->getGroups()->toArray()] 
    ); 
} 

return $result;