gpt4 book ai didi

doctrine-orm - Doctrine DBAL 查询构建器省略了一些连接

转载 作者:行者123 更新时间:2023-12-04 06:15:23 25 4
gpt4 key购买 nike

PHP 代码:

    $xCodesQueryBuilder = $conn->createQueryBuilder();

$xCodesQueryBuilder->select("l.id","mdsh.xcode","mdso.xcode")
->from("location_tree","l")
->join("l","location_tree_pos","p","l.id = p.tree_id")
->rightJoin("l","hotel","h","h.location_id = l.id")
->leftJoin("l","offer_location","ol","l.id=ol.location_id")
->leftJoin("ol","mds_offer","mdso","ol.offer_id = mdso.offer_id")
->leftJoin("h","mds_hotel","mdsh","h.id = mdsh.hotel_id")
->where("p.parent_id IN (:ids)")
->andWhere("(mdso.xcode IS NOT NULL OR mdsh.xcode IS NOT NULL)");

var_dump($xCodesQueryBuilder->getSQL());exit;

结果:

SELECT l.id, mdsh.xcode, mdso.xcode
FROM location_tree l
INNER JOIN location_tree_pos p ON l.id = p.tree_id
RIGHT JOIN hotel h ON h.location_id = l.id
LEFT JOIN offer_location ol ON l.id=ol.location_id
WHERE (p.parent_id IN (:ids))
AND ((mdso.xcode IS NOT NULL OR mdsh.xcode IS NOT NULL))

为什么省略了最后两个连接的任何想法?

最佳答案

我刚刚得到了这个为我工作。不得不修改函数getSQLForSelect()QueryBuilder.php .

我开了一个 ticket并向 DBAL 提交了拉取请求,但同时,请随意使用 my patched copy .

更新:

刚刚意识到解决此问题的另一种方法是始终使用 FROM表别名作为第一个参数( $fromAlias )在任何 join() 中方法。

在您的情况下,您可以将代码更改为如下所示:

$xCodesQueryBuilder = $conn->createQueryBuilder();

$xCodesQueryBuilder->select("l.id","mdsh.xcode","mdso.xcode")
->from("location_tree","l")
->join("l","location_tree_pos","p","l.id = p.tree_id")
->rightJoin("l","hotel","h","h.location_id = l.id")
->leftJoin("l","offer_location","ol","l.id=ol.location_id")
->leftJoin("l","mds_offer","mdso","ol.offer_id = mdso.offer_id")
->leftJoin("l","mds_hotel","mdsh","h.id = mdsh.hotel_id")
->where("p.parent_id IN (:ids)")
->andWhere("(mdso.xcode IS NOT NULL OR mdsh.xcode IS NOT NULL)");

var_dump($xCodesQueryBuilder->getSQL());exit;

关于doctrine-orm - Doctrine DBAL 查询构建器省略了一些连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7331117/

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