【发布时间】:2017-06-13 08:45:07
【问题描述】:
我在表中遇到关于左连接查询的问题 与其他表没有关系,所以当我加入时 收到 500 内部服务器错误,但是当我与其他 2 有关系而不是工作的表。我试图创建别名 使用不同的方式,如 Leftjoin('BundleName:Entity', 'alias') 但不是 工作。我有5个表如下,关系定义为 下面。
客户:
id - 主键
客户名称
客户名称
site:
id - Primary key
site name
site details
report:
id - Primary key
site_id - Foreign key of site table
client_id - Foreign key of client table
title
description
report_call_out
id- Foreign key of Report table
call title
call detail
report_works
id- Foreign key of Report table
works title
works detail
These are the relationship in my database so I am getting all list from Report table when I am doing Left Join with other table like report_call_out and report_works which has no relationship from report table than I am getting internal server error but without adding both table in Join, Rest of 2 tables(Client and site) join working fine.
Can you please guide me that where I am having issue.?
I am using below code to populate all list of records.
$qb = $this->createQueryBuilder('r')
->leftJoin('r.client', 'c')
->leftJoin('r.site', 's');
在此代码之后,我使用此代码 (echo $qb->getQuery()->getDQL();) 以 DQL 格式打印查询,但它没有显示与 report_call_out 表和 report_works 表的任何左连接。
但是,当我使用此代码 ($qb->getQuery()->getSQL();) 以 SQL 格式打印查询时,它将自动在查询中添加左联接,并使用两个表 report_call_out 和 report_works。
【问题讨论】:
-
你在哪里打电话给
$qb = $this->createQueryBuilder('r')?此外,“500 Internal Server Error”并不是一个非常详细的信息。我假设某个地方抛出了异常。请提供更多详细信息。 -
@W0rma,我从 ReportRepository 文件中调用 $qb = $this->createQueryBuilder('r') 。我想使用 report_call_out 表字段来过滤结果
-
请提供有关所引发异常的更多详细信息。 “500 内部服务器错误”不是很有帮助
-
当我为 report_call_out 添加 leftJoin 时,出现 500 错误
标签: php mysql symfony doctrine left-join