我有两个表,客户和订单(oneToMany)。我需要选择所有客户(作为对象)并添加到客户对象orderTotal字段。我创建了这样的查询:
return $this->createQueryBuilder('c')
->select('c as customer', 'COUNT(o.id) as totalOrders')
->join('c.orders', 'o')
->groupBy('c.id')
->getQuery()->getResult();
但是学说让我回答:
array:2 [▼
0 => array:2 [▼
"customer" => Customer {#748 ▶}
"totalOrders" => "49"
]
1 => array:2 [▼
"customer" => Customer {#777 ▶}
"totalOrders" => "50"
]
]
如何更改此查询并将“totalOrders”移动到Customer对象?