【问题标题】:The class 'Doctrine\ODM\MongoDB\Cursor' was not found in the chain configured namespaces AppBundle\Document在链配置的命名空间 AppBundle\Document 中找不到类 'Doctrine\ODM\MongoDB\Cursor'
【发布时间】:2016-10-31 01:51:26
【问题描述】:

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

<?php

namespace AppBundle\Repository;

use Doctrine\ODM\MongoDB\DocumentRepository;

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 'Doctrine\ODM\MongoDB\Cursor' was not found in the chain configured namespaces AppBundle\Document 

有什么问题?

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

【问题讨论】:

标签: mongodb symfony doctrine-orm query-builder odm


【解决方案1】:

$cat 变量是Doctrine\ODM\MongoDB\Cursor 的实例。但它应该是文档的实例。 所以代码应该改为:

<?php

namespace AppBundle\Repository;

use Doctrine\ODM\MongoDB\DocumentRepository;

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;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-02
    • 2015-11-12
    • 1970-01-01
    相关资源
    最近更新 更多