在链配置的命名空间 AppBundle\Document 中找不到类'DoctrineODMMongoDBCursor'



在一个存储库中,我有这样的代码:

<?php
namespace AppBundleRepository;
use DoctrineODMMongoDBDocumentRepository;
class ItemRepository extends DocumentRepository
{
    public function findAllQueryBuilder($filter = '')
    {
        $qb = $this->createQueryBuilder('item');
        if ($filter) {
            $cat = $this->getDocumentManager()
                ->getRepository('AppBundle:Category')
                ->findAllQueryBuilder($filter)->getQuery()->execute();

            $qb->field('category')->includesReferenceTo($cat);
        }
        return $qb;
    }
}

但是它抛出了这个错误:

The class 'DoctrineODMMongoDBCursor' was not found in the chain configured namespaces AppBundleDocument 

有什么问题吗?

我检查了$cat,它返回正确的category文档。

$cat变量为DoctrineODMMongoDBCursor的实例。但它应该是文档的实例。所以代码应该改成:

<?php
namespace AppBundleRepository;
use DoctrineODMMongoDBDocumentRepository;
class ItemRepository extends DocumentRepository
{
    public function findAllQueryBuilder($filter = '')
    {
        $qb = $this->createQueryBuilder('item');
        if ($filter) {
            $cats = $this->getDocumentManager()
                ->getRepository('AppBundle:Category')
                ->findAllQueryBuilder($filter)->getQuery()->execute();
            foreach ($cats as $cat) {
                $qb->field('category')->includesReferenceTo($cat);
            }
        }
        return $qb;
    }
}

相关内容

  • 没有找到相关文章

最新更新