如何对这个Cakephp查询进行计数?
$matches = $this->Product->find('count', array(
'conditions' => array(
"Product.brand_id" => $brand['Brand']['id'],
'Product.active' => 1
));
答案 0 :(得分:5)
这样的东西?
$matches = $this->Product->find('count', array(
'fields' => 'DISTINCT Product.brand_id',
'conditions' => array("Product.brand_id" => $brand['Brand']['id'],
'Product.active' => 1)
));