doctrine2 - Doctrine 2: Cannot select entity through identification variables without choosing at least one root entity alias -
rather actual question, sticky note myself, may others. there many other similar questions: 1, 2, 3, 4, 5, 6, none of them seems offer solution.
i have following entities:
class order { // ... /** * @manytoone(targetentity="customer") * @var customer */ private $customer; /** * @column(type="integer") * @var int */ private $amount; } class customer { // ... }
order
has unidirectional, many-to-one relationship customer
. want every customer, along total amount of orders, run following dql query:
select c, sum(o.amount) model\order o join o.customer c group c
but following error:
[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 @ least 1 root entity alias.
how can fix it?
this known doctrine limitation.
the solution explicitly select
entity want retrieve (customer
) , manually join other entity (order
) there, using with
condition:
select c, sum(o.amount) model\customer c join model\order o o.customer = c group c
Comments
Post a Comment