gpt4 book ai didi

doctrine-orm - 教义 2 : Cannot select entity through identification variables without choosing at least one root entity alias

转载 作者:行者123 更新时间:2023-12-04 03:48:29 25 4
gpt4 key购买 nike

这不是一个实际的问题,而是给我自己的便利贴,可以帮助其他人。还有很多其他类似的问题:1 , 2 , 3 , 4 , 5 , 6 ,但他们似乎都没有提供这种解决方案。

我有以下实体:

class Order
{
// ...

/**
* @ManyToOne(targetEntity="Customer")
*/
private Customer $customer;

/**
* @Column(type="integer")
*/
private int $amount;
}

class Customer
{
// ...
}
OrderCustomer 具有单向、多对一的关系.我想获取每个客户以及他的订单总额,因此我运行以下 DQL 查询:
SELECT c, SUM(o.amount)
FROM Model\Order o
JOIN o.customer c
GROUP BY c
但我收到以下错误:

[Doctrine\ORM\Query\QueryException]
[Semantical Error] line 0, col -1 near 'SELECT c, SUM(o.amount)': Error: Cannot select entity through identification variables without choosing at least one root entity alias.


我该如何解决?

最佳答案

这是一个已知的 Doctrine 限制。

解决方案是明确SELECT您要检索的实体 ( Customer ) 并使用 Order 从那里手动加入另一个实体 ( WITH )条件:

SELECT c, SUM(o.amount)
FROM Model\Customer c
JOIN Model\Order o WITH o.customer = c
GROUP BY c

关于doctrine-orm - 教义 2 : Cannot select entity through identification variables without choosing at least one root entity alias,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46206968/

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