2013-12-02 3 views
2

Как можно сделать этот запрос Cakephp, чтобы считать отличным?Cake php count distinct

 $matches = $this->Product->find('count', array(
      'conditions' => array(
       "Product.brand_id" => $brand['Brand']['id'], 
       'Product.active' => 1 

     )); 

ответ

5

Нечто подобное?

$matches = $this->Product->find('count', array(
    'fields' => 'DISTINCT Product.brand_id', 
    'conditions' => array("Product.brand_id" => $brand['Brand']['id'], 
      'Product.active' => 1) 
    )); 
+0

Вместо этого я рекомендую использовать здесь виртуальное поле. И группа по заявлению. – mark