0

使用带有PHPCR-ODM的 Document 类,可以使用类存储库获取结果,结果自动按sort_order不在 Document 类中但在数据库模式中的字段排序。

Symfony Profiler 中记录的查询示例:

SELECT path FROM phpcr_nodes WHERE parent = ? AND workspace_name = ? ORDER BY sort_order ASC

我用 queryBuilder 构建了这个简单的查询:

$qb->from()
        ->document('AppBundle\Document\Product', 'product')
        ->end()
        ->where()
        ->neq()->field('product.type')->literal('category');
$query = $qb->getQuery();

结果不像其他查询那样按字段排序sort_order,我不能使用该orderBy方法,因为这不是 Document 类的字段。

那么,我怎样才能对我的结果进行排序呢?

4

1 回答 1

0

谁说不能用orderBy()?您应该阅读文档,因为这当然是可能的。使用相同的代码并假设排序列sort_order如下所示:

$qb->from()
   ->document('AppBundle\Document\Product', 'product')
   ->end()
   ->where()
   ->neq()->field('product.type')->literal('category')
   ->orderBy()->desc()->field('product.sort_order');
于 2017-12-19T15:07:45.440 回答