0
我使用查找來總結表事件的字段num_days時遇到問題。Cakephp表查詢:SUM返回0
$events = TableRegistry::get('Events');
$query = $events->find('all')
->select(['used' => 'sum(num_days)'])
->first();
爲什麼$query->used
總是0?
print_r($events->find('all')->select(['used' => 'sum(num_days)'])->toArray())
給人,
Array ([0] => App\Model\Entity\Event Object ([used] => 6 [[new]] => [[accessible]] => Array ([*] => 1) [[dirty]] => Array () [[original]] => Array () [[virtual]] => Array () [[errors]] => Array () [[invalid]] => Array () [[repository]] => Events))
6恰好是用於查詢的正確答案和print_r的顯示,但$查詢 - >使用總是返回0。
是什麼問題? –
@Mahesh Singh Chouhan問題在於$ query-> used沒有返回6. – user2526028
嘗試'$ query-> order(['used'=>'DESC']);'在'$ query-> used'之前' –