0

I'm searching in Sonata doc but I can't find if it is possible.

I have an Entity Question with one to many relation with Answer.

In my ListMapper for QuestionAdmin, I would like to do something like :

$listMapper
  ->addIdentifier('title')
  ->add('countAnswers', IntegerType::class, array(
     'action', 'getCountAnswers'
        )
  );

I know the code below is wtf but I have no idea if this is possible or how to do it ?

Aximem
  • 714
  • 8
  • 27

1 Answers1

2

if you just want to display the value in the admin list you could extend you entity with a simple getAnswersCount function and reference this field (function) in the admin:

example reference:

AppBundle\Entity\Questions

public function getAnswersCount() 
{
    return $this->getAnswers()->count();
}

QuestionAdmin

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('title')
        ->add('answersCount')
    ;
}
lordrhodos
  • 2,689
  • 1
  • 24
  • 37