繁体   English   中英

LeftJoin别名创建问题,与另一个表格无关

[英]LeftJoin Alias Creation issue without relationship with another table Doctrine Symfony

我在表中遇到与左连接查询有关的问题,而表与其他表没有关系,所以当我进行连接而不是得到500个内部服务器错误时,但是当我正在处理其他两个与工作无关的表时,我试图创建别名具有与Leftjoin('BundleName:Entity','alias')不同的方式,但无法正常工作。我有以下5个表,并定义了以下关系。

客户:
id-主键客户端fname客户端lname

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表的左连接。

但是,当我使用此代码以SQL格式打印查询时($ qb-> getQuery()-> getSQL();),它将自动在查询中添加左联接,同时使用表report_call_out和report_works。

你可以这样使用

$qb = $this->createQueryBuilder('r')
                       ->leftJoin('r.client', 'c')
                       ->leftJoin('AcmeReportBundle:report_call_out', 'rc','WITH','r.id = rc.id')
                       ->leftJoin('r.site', 's'); 

使用“ WITH”连接外部表。 report_id为FK

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM