イベント エンティティと参加者エンティティの間に一対一の関係があります。私のコントローラーでは、次のことができます:
$participants = $event->getParticipant();
しかし、今はプロパティvisible
の値が 1 の参加者のみが必要です。
どうすればそれらのコレクションを入手できますか? 参加者はparticipant.event_id = event.id
、イベント エンティティ内のすべての参加者の配列コレクションであるためです。
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