I have a form that consist of an entity field like bellow
$builder->add('rating', 'entity', array(
'class' => 'MyBundle:Rating',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.id', 'ASC');
},
In this form I can use a query builder to have a custom selection of Rating entity. But since I have a custom repository for Rating entity like bellow, I want to use the loadAllRoots() method in the RatingRepository class for filling the rating entity in my form instead of using query builder.
class RatingRepository extends EntityRepository
{
public function loadAllRoots()
{
return $this->getEntityManager()
->createQuery('SELECT r FROM MyBundle:Rating r WHERE r.parent IS NULL')
->getResult();
}
Best