Repository query->setLimit(4) returns 某些情况下没有结果

Repository query->setLimit(4) returns no result in some cases

在我的扩展存储库中,我有以下代码:

function findByTyp($typ, $not, $gender) {
         $query = $this->createQuery();
         return $query->matching(
                        $query->logicalAnd(
                            $query->equals('pid', 96),
                            $query->equals('typ', $typ),
                            $query->logicalNot($query->equals('uid', $not)),
                            $query->equals('gender', $gender)
                        )
                    )
                    ->setOrderings (Array('sort' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING))
                    ->setLimit(4)
                    ->execute();
    }

现在在特定情况下,这应该 return 包含 1 个项目的查询。但不知何故,它没有 return 任何项目。但是当我删除 ->setLimit(4) 时,它 return 是正确的项目。

现在这对我来说意义不大。与其他情况一样,它按应有的方式工作。那么,当没有超过 4 个项目(在本例中只有 1 个)时,->setLimit(4) 如何从查询中删除项目

到目前为止我找不到答案所以这是我的

解决方法:

我不使用存储库中的 ->setLimit(4),但只使用模板中的前 4 项:

<f:for each="{collection}" as="collectionItem" iteration="collectionCount">
        <f:if condition="{collectionCount.index}<4">
              ....
        </f:if>
    </f:for>