gpt4 book ai didi

php - 与另一个表没有关系的 LeftJoin 别名创建问题 Doctrine Symfony

转载 作者:行者123 更新时间:2023-11-29 18:47:41 25 4
gpt4 key购买 nike

I am facing issue regarding Left join query in doctrine while table have no relation with other tables so when I am doing join than getting 500 internal server error but when I am doing with other 2 tables which have relation than working.I have tried to create alias with different way like Leftjoin('BundleName:Entity', 'alias') but not working.I have 5 tables as below and there relation are defined as below.

客户:
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');

在此代码之后,我使用此代码以 DQL 格式打印查询(echo $qb->getQuery()->getDQL();),并且它没有向我显示与 report_call_out 表和 report_works 表的任何左连接。

但是当我使用此代码($qb->getQuery()->getSQL();)以 SQL 格式打印查询时,它会自动在带有表 report_call_out 和 report_works 的查询中添加 Left Join。

最佳答案

你可以这样使用

$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

关于php - 与另一个表没有关系的 LeftJoin 别名创建问题 Doctrine Symfony,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44516481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com