左父连接与父库中的子类Symfony
问题描述:
我试图做左连接与父类(报表)存储库中的子类比得到'500内部服务器错误'。我正在做这样的如下。 此处ReportCallOut表'id'(PK)字段是报表'id'(PK)的外键。左父连接与父库中的子类Symfony
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;
}
答
检查这个代码,如果没有工作,然后分享 “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);
+0
我收到错误“未捕获的异常:请求堆栈为空” – Bhavik
正如你使用Symfony:你的app.log或dev.log是什么意思?你应该得到那个PHP错误来继续。您可以在 /var/logs/dev.log或 /var/logs/prod.log中找到它,具体取决于您的设置。 –
Fuzzzzel
我已经在dev.log文件中检查过,但没有任何内容。 – Bhavik
根据我的假设,我在左连接的语法上做了一些错误。我想要和子类一起加入。 – Bhavik