我要運行這段代碼,它嵌套了關聯數據:如何顯示嵌套組合值的CakePHP 3
'VhpProducts.VhpHasilPencapaian',
'Departments.VhpHasilPencapaian',
'Groups.VhpHasilPencapaian' and to sum 'VhpHasilPencapaian.quantity'
但我得到的是
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'VhpHasilPencapaian.amount' in 'field list'
$vhpCriteria = $this->VhpCriterias->find('all', [
'contain' => [
'VhpProducts.VhpHasilPencapaian',
'Departments.VhpHasilPencapaian',
'Groups.VhpHasilPencapaian'
],
'field' => ['VhpProducts.name']
]);
$vhpCriteria->select([
'product' => 'VhpProducts.name',
'amountTotal' => $vhpHasilPencapaian->func()->sum('VhpHasilPencapaian.amount'),
'qty' => $vhpHasilPencapaian->func()->sum('VhpHasilPencapaian.quantity'),
]);
最有可能'VhpHasilPencapaian'和/或父關聯不是1:1/n:1,所以它不會在主查詢中結束!?您應該提供關於關聯的更多信息以及您正在查找的結果SQL查詢。 – ndm
@ndm我有VhpCriterias表與VhpProduct,部門和組具有關聯(一對多)。在那之後,我有VhpHasilPencapaian表,它也與VhpProduct,Departments和Groups有關聯。所以我想顯示VhpHasilPencapaian的數據,並總結他們 –