CakePHP - 从表中检索大多数出现的值

I have a simple table called 'Services'.

Each record consists simply of an ID and 'service_name'.

These services are then use by customers in the 'Customers table', linked by the Service ID.

How would I grab the most commonly used services from the 'Customers' table using cake?

Use a CounterCache Field

You can also group by that field and get a COUNT() then lookup the services.

$services = $this->Service->find('all');
$services = Hash::combine($services, '{n}.Service.id', '{n}.Service');

$service_counts = $this->Customer->find('all', array(
    'fields' => array('Customer.service_id', 'COUNT(*) AS count'),
    'group'  => 'Customer.service_id',
));

foreach($service_counts as $service) {
    $services[$service['Customer']['service_id']]['Service']['count'] = $service[0]['count'];
}