0
我試圖獲得每個商店的評論數,並且真的停留在這一步。
是否可以做到這一點,以及如何?在CakePHP3上構建查詢
public function display()
{
$this->loadModel('Shops');
$shoplist=$this->Shops->find('all')->order(['title' => 'DESC', 'id' => 'ASC'])->contain([
'Comments' => function ($q) {
return $q->select('id')->where(['published' => 1])->count();
}]);;
$this->set('shoplist', $shoplist);
}
回$ Q->選擇([ '數'=> $ Q-> FUNC() - >計數( '*' )]; –