1

イベント エンティティと参加者エンティティの間に一対一の関係があります。私のコントローラーでは、次のことができます:

$participants = $event->getParticipant();

しかし、今はプロパティvisibleの値が 1 の参加者のみが必要です。

どうすればそれらのコレクションを入手できますか? 参加者はparticipant.event_id = event.id、イベント エンティティ内のすべての参加者の配列コレクションであるためです。

4

1 に答える 1

1

EventRepository目に見える参加者のみをイベントに参加させるメソッドを簡単に作成できます。

// YourBundle/Entity/EventRepository.php

public function getEventFilterVisibleParticipants($event_id)
{
    return $repository->createQueryBuilder('event')
        ->where('event.id = :event_id')
        ->leftJoin('event.participants', 'participant', 'WITH', 'participant.visible = :visibility')
        ->setParameter('event_id', $event_id)
        ->setParameter('visibility', 1)
        ->orderBy('event.startDate', 'DESC')
        ->getQuery()
        ->getResult()
    ;
}

...コントローラーで次のようにします:

$event = $this
    ->getDoctrine()
    ->getRepository('YourBundle:Event')
    ->getEventFilterVisibleParticipants($id)
;

$participants = $event->getParticipants(); // returns the filtered collection
于 2013-10-26T13:11:14.223 に答える