Php 如何使用Doctrine2统计相关表记录

Php 如何使用Doctrine2统计相关表记录,php,mysql,symfony,join,doctrine-orm,Php,Mysql,Symfony,Join,Doctrine Orm,我对教义很陌生,我想执行一项特定的任务 我有jobs表,其中有category\u id列,显然还有categories表 在Symfony2中,我有这个存储库 <?php namespace Ibw\JobeetBundle\Repository; use Doctrine\ORM\EntityRepository; class CategoryRepository extends EntityRepository { public function getWithAllJ

我对教义很陌生,我想执行一项特定的任务

我有
jobs
表,其中有
category\u id
列,显然还有
categories

在Symfony2中,我有这个存储库

<?php

namespace Ibw\JobeetBundle\Repository;

use Doctrine\ORM\EntityRepository;

class CategoryRepository extends EntityRepository
{
    public function getWithAllJobs()
    {
        $qb = $this->createQueryBuilder('c')
                    ->select('c, j')
                    ->leftJoin('c.jobs', 'j');
        return $qb->getQuery()->getResult();
    }

}

唯一正确的方法是使用
内部连接
而不是
左连接
。您的代码应该如下所示:

    $qb = $this->createQueryBuilder('c')
                ->select('c, j')
                ->innerJoin('c.jobs', 'j');