我试图在父(Report)存储库中使用子类来执行leftJoin而不是获取' 500内部服务器错误'。我这样做如下。 这里ReportCallOut表' id'(PK)字段是报告表' id'(PK)的外键。
class ReportRepository extends EntityRepository
{
public function getPage($page = 1, $perPage = null, $filter = null) {
$qb = $this->createQueryBuilder('r')
->leftJoin('r.client', 'c')
->leftJoin('ACMEModulesReportCentreBundle:ReportCallOut', 'rc', 'WITH', 'r.id=rc.id')
->leftJoin('r.site', 's')
->leftJoin('r.status', 'st');
}
在我打印$ qb-> getQuery() - > getSQL()时添加leftJoin之后比得到500内部服务器错误。
ReportController.php
class ReportCentreController extends ModuleController
{
public function indexAction(Request $request, $page)
{
$request->getSession()->set('signBack', $request->getUri());
$reportsRepository = $this->getDoctrine()
->getRepository('ACMEModulesReportCentreBundle:Report');
$perPage = $this->container->getParameter('pagination_per_page');
$filter = $this->get('acme_core.filters')->getFilter();
$filter['division'] = $this->division;
if ($this->isGranted('ROLE_REPORT_CENTRE_CAN_VIEW_OWN_REPORTS', $this->module)) {
$filter['createdBy'] = $this->getUser();
}
$reportsPaginator = $reportsRepository->getPage($page, $perPage, $filter);
}
}
ReportRepository.php
class ReportRepository extends EntityRepository
{
public function getPage($page = 1, $perPage = null, $filter = null) {
$qb = $this->createQueryBuilder('r')
->leftJoin('r.client', 'c')
->leftJoin('r.site', 's')
->leftJoin('r.status', 'st');
}
Report.php
abstract class Report {
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Gedmo\Versioned
* @ORM\Column(type="string", length=255, nullable=true)
*/
}
ReportCallOut.php
class ReportCallOut extends Report {
// protected $locked = false;
/**
* @Gedmo\Versioned
* @ORM\Column(type="date", nullable=true)
*/
private $date;
/**
* @Gedmo\Versioned
* @ORM\Column(type="time", nullable=true)
*/
private $time;
/**
* @Gedmo\Versioned
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $job;
}
答案 0 :(得分:0)
检查此代码,如果不起作用,则分享您的实体文件" ReportCallOut"和"客户"。
$em = $this->getDoctrine()->getManager();
$clientRepository = $em->getRepository("AppBundle:client");
$where = ' c.cId=:id and c.cStatus !=9 ';
if (!empty($searchKey)) {
$where .= " AND (r.rName LIKE '%" . $searchKey . "%'
OR c.cFirstName LIKE '%" . $searchKey . "%'
OR c.cLastName LIKE '%" . $searchKey . "%') ";
}
$qb = $this->createQueryBuilder('r')
->select('r.rId,c.cId')
->leftJoin('r.client', 'c')
->leftJoin('ACMEModulesReportCentreBundle:ReportCallOut', 'rc', 'WITH', 'r.rId=rc.rcId')
->leftJoin('r.site', 's')
->leftJoin('r.status', 'st')
->where($where)
->setParameter('id', $id)
->getQuery();
$resultData = $qb->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);