Using a Document class with PHPCR-ODM, it is possible to fetch results with the class repository, the results are automatically sorted by a field sort_order
that is not in the Document class but in the database schema.
Example of a query logged in the Symfony Profiler:
SELECT path FROM phpcr_nodes WHERE parent = ? AND workspace_name = ? ORDER BY sort_order ASC
I have this simply query built with queryBuilder :
$qb->from()
->document('AppBundle\Document\Product', 'product')
->end()
->where()
->neq()->field('product.type')->literal('category');
$query = $qb->getQuery();
The result is not sorted by the field sort_order
like other queries, and I can't use the orderBy
method as this is not a field of the Document class.
So, how can I sort my results?
Who said you can't use
orderBy()
? You should read the docs because certainly it's possible. Using your same code and assuming the sort column assort_order
see below: