/**
  * Removes 'fields' key 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()
  */
 public function _findPaginatecount($state, $query, $results = array())
 {
     if ($state == 'before' && isset($query['operation'])) {
         if (!empty($query['fields']) && is_array($query['fields'])) {
             if (!preg_match('/^count/i', $query['fields'][0])) {
                 unset($query['fields']);
             }
         }
     }
     return parent::_findCount($state, $query, $results);
 }