How to use orderBy param on find_method findAll with Doctrine ObjectSelect

0 Flares Twitter 0 Facebook 0 LinkedIn 0 0 Flares ×

The docs offer an example for an extended version of the DoctrineModule\Form\Element\ObjectSelect:

This find_method parameters allow you to order and sort the result of your repository method.

 

Unfortunately this will not work when using the findAll method. But why?

Looking at the source code of the Doctrine ORM you can see that unlike the findBy method findAll does not allow passing arguments for filtering, sorting nor limiting:

https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/EntityRepository.php#L157-182

 

But there is a workaround:

Use the findBy() method instead and simply pass an empty array for the criteria parameter.

 

That’s it!

 

Backlinks:

Web Deviloper