我正在使用ezpublish Search API获取按父字段排序的session内容类型对象列表(字段名为training)。
因此,如果我有两个会话S1(链接到代码T1的培训)和S2(链接到代码T2的培训),我希望会话S1在列表中的S2之前列出。

$criterions = array (
            new Criterion\ContentTypeIdentifier( 'session' )
        );
$locationQuery = new LocationQuery();
        $locationQuery->query = $criteriaArray;
        $locationQuery->sortClauses = array(
            //new SortClause\Field('session','price'),<- this works
            new SortClause\Field('training','code',Query::SORT_ASC)
           //this second sorClause does not work as code is not a field of session while price is
            );

使用本机mysql查询可能可以解决此问题,但它不可移植,有些id将被硬编码。
我的问题是,我们能根据他们父母的“代码”字段实现一种“代码”类型吗?

最佳答案

对于内置的sort子句,这是不可能的。
您可以做的是获取按code字段排序的培训,然后为每个培训分别加载其会话。当然,如果您的数据库中有许多内容对象,那么这将不高效。
另一种可能是实现一个custom sort clause可能会成功。

关于php - ezpublish 5.4根据父字段排序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49728422/

10-12 12:59
查看更多