CakePHP 3.6:计算来自 table 的不同记录

CakePHP 3.6: Count distinct records from table

我正在尝试使用 where 条件对 table 进行不同的计数。

这是我试过的:

$customerServiceTypes = TableRegistry::get('CustomerServiceTypes');
$customers_count = $customerServiceTypes->find('all', array(
            'fields' => 'DISTINCT CustomerServiceType.customer_id',
            'conditions' => array("CustomerServiceTypes.service_type_id" => $id)))->count();

但是它不起作用。我得到 25 作为结果,但它应该是 2Distinct 不工作。

$customerServiceTypes = TableRegistry::get('CustomerServiceTypes');
$customers_count = $customerServiceTypes->find()
     ->select(['customer_id'])
     ->distinct()
     ->where(['service_type_id =' => $id])->count();