문제

maybe I'm to stupid for this, but I want to get a many to many result set from my database with propel.

I've a Acl_Customer, Acl_Group and a Acl_Customer_Group table. The last one is the cross-ref between a customer and a group.

Now, I just want to be able to fetch my acl customers with a join on the groups table.

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

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

This brings me the following:

[{"id":1,"username":"foo","email":"bar@baz.quux"}]

But I need something like this:

[{"id":1,"username":"foo","email":"bar@baz.quux","groups":[{"name":"developer"}, ...]}]

Has anyone an idea?

도움이 되었습니까?

해결책

You can not "join" n-to-n relations in SQL. You have to fire a extra query, means:

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

return $result;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top