0
而不是一個實際的問題,這是一個便箋,可以幫助他人。還有很多其他類似的問題:1,2,3,4,5,6,但他們都沒有提供這種解決方案。原則2:不能選擇實體通過識別變量而不選擇至少一個根實體別名
我有以下實體:
class Order
{
// ...
/**
* @ManyToOne(targetEntity="Customer")
* @var Customer
*/
private $customer;
/**
* @Column(type="integer")
* @var int
*/
private $amount;
}
class Customer
{
// ...
}
Order
有一個單向的,多到一個與Customer
關係。我想每一個客戶,他的訂單總金額一起,所以我運行下面的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.
我該如何解決?