我已经在那里它会检索所有相关的博客节上我的项目类别此symfony的代码:如何使用symfony2原则查询生成器来选择不同的查询?
$category = $catrep->createQueryBuilder('cc')
->Where('cc.contenttype = :type')
->setParameter('type', 'blogarticle')
->getQuery();
$categories = $category->getResult();
这工作,但查询包括重复:
Test Content
Business
Test Content
我想使用DISTINCT
命令在我的查询中。我见过的唯一示例要求我编写原始SQL。我想尽可能避免这种情况,因为我试图保持所有代码都一样,所以它们都使用Symfony2/Doctrine提供的QueryBuilder功能。
我尝试添加distinct()
到我的查询是这样的:
$category = $catrep->createQueryBuilder('cc')
->Where('cc.contenttype = :type')
->setParameter('type', 'blogarticle')
->distinct('cc.categoryid')
->getQuery();
$categories = $category->getResult();
但它会导致以下错误:
Fatal error: Call to undefined method Doctrine\ORM\QueryBuilder::distinct()
我如何告诉symfony中选择不同?
你应该传递一个布尔值不同()函数。 http://www.doctrine-project.org/api/orm/2.2/class-Doctrine.ORM.QueryBuilder.html#_distinct – Omn