0

In a repository I have this code:

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

But it throw this error:

The class 'Doctrine\ODM\MongoDB\Cursor' was not found in the chain configured namespaces AppBundle\Document 

What is the problem?

I checked the $cat, it returns correct category document.

Arash Mousavi
  • 2,110
  • 4
  • 25
  • 47
  • could you add where you defined your entity and the ORM config part ? this answer may help you http://stackoverflow.com/questions/22813300/symfony-error-the-class-xxx-was-not-found-in-the-chain-configured-namespaces-xxx – zizoujab Jun 28 '16 at 21:10

1 Answers1

0

The $cat variable is the instance of Doctrine\ODM\MongoDB\Cursor. but it should be instance of document. So the code should change to:

<?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;
    }
}
Arash Mousavi
  • 2,110
  • 4
  • 25
  • 47