问题
When using a Doctrine_Table object, is it possible to specify the order of the returned collection when using findAll() or findByWhatever()?
In the doc's I see some stuff about getOrderByStatement() and processOrderBy() but it isn't clear on how to use them...
回答1:
You can also leave the first array blank
$em->getRepository('BackendDestinyBundle:Destiny')->findBy(array(), array('title'=>'asc'));
回答2:
You can in fact specify a default order by in your schema:
Foo:
columns:
...
options:
orderBy: bar DESC
Note that when you want to specify a different order, you can still create a query and override the default order by.
回答3:
According to Jon Wage you should create a Query in this Case… Found in the mailing-list
回答4:
In my case, the problem was that i had a statement like this
$destinos = $em->getRepository('BackendDestinyBundle:Destiny')->findAll();
finaly I changed it to a CreateQuery statement, it does exactly the same but i can put a OrderBy sentence
$destinos = $em->createQuery("SELECT d FROM BackendDestinyBundle:Destiny d order by d.name")->getResult();
来源:https://stackoverflow.com/questions/7124340/doctrine-coregettable-findall-how-to-specify-order