I want to left join three entities in the sonata admin list view and I didn't annotate the relationship of the three entities in my entity class.I try to join two tables, which are Event and Participant, but it return me double rows of the results. Does anyone face this problem before or can give me any suggestions about how to solve this problem?
Event.php
class Event
{
/**
* @var integer
*
* @ORM\Column(name="event_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=200)
*/
protected $eventTitle;
...
}
Participant.php
class Participant
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $eventID;
/**
* @ORM\Column(type="string", length=30)
* @Assert\NotBlank(message="Name should not be blank.")
* @Assert\Length(min=5, max=30)
*/
protected $name;
...
}
Payment.php
class Payment
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=30)
*/
protected $userID;
/**
* @ORM\Column(type="string", length=30)
*/
protected $bank;
...
}
ParticipantAdmin.php
class ParticipantAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('name')
->add('email')
->add('eventTitle')
;
}
public function createQuery($context = 'list') {
$em = $this->getConfigurationPool()
->getContainer()
->get('Doctrine')
->getEntityManager();
$query = $em->createQueryBuilder()
->select('a', 'u')
->from('AppBundle\Entity\Participant', 'a')
->leftJoin(
'AppBundle\Entity\Event',
'u',
\Doctrine\ORM\Query\Expr\Join::WITH,
'a.eventID = u.id'
)
;
$proxyQuery = new ProxyQuery($query);
return $proxyQuery;
}
}