function _findCount($state, $query, $results = array()) { if ($state == 'before') { if (isset($query['type']) && $query['type'] != 'count') { $query = $this->{'_find' . ucfirst($query['type'])}($state, $query); } return parent::_findCount($state, $query); } return parent::_findCount($state, $query, $results); }
/** * Removes 'fields' key and 'contain' from count query on custom finds when it is an array, * as it will completely break the Model::_findCount() call * * @param string $state Either "before" or "after" * @param array $query * @param array $data * @return int The number of records found, or false * @access protected * @see Model::find() */ function _findCount($state, $query, $results = array()) { if ($state == 'before' && isset($query['operation'])) { $this->findQueryType = 'count'; if (!empty($query['fields']) && is_array($query['fields'])) { if (!preg_match('/^count/i', $query['fields'][0])) { unset($query['fields']); } } if (isset($query['contain'])) { unset($query['contain']); } } return parent::_findCount($state, $query, $results); }