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');