在一个存储库中,我有这样的代码:
<?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;
}
}