group() public method

Fields can be passed as an array of strings, array of expression objects, a single expression or a single string. By default this function will append any passed argument to the list of fields to be grouped, unless the second argument is set to true. ### Examples: Produces GROUP BY id, title $query->group(['id', 'title']); Produces GROUP BY title $query->group('title');
public group ( array | Cake\Database\ExpressionInterface | string $fields, boolean $overwrite = false )
$fields array | Cake\Database\ExpressionInterface | string fields to be added to the list
$overwrite boolean whether to reset fields with passed list or not
Example #1
0
 /**
  * Returns the passed query after rewriting the DISTINCT clause, so that drivers
  * that do not support the "ON" part can provide the actual way it should be done
  *
  * @param \Cake\Database\Query $query The query to be transformed
  * @return \Cake\Database\Query
  */
 protected function _transformDistinct($query)
 {
     if (is_array($query->clause('distinct'))) {
         $query->group($query->clause('distinct'), true);
         $query->distinct(false);
     }
     return $query;
 }
Example #2
0
 public function beforeFind(Event $event, Query $query, ArrayObject $options)
 {
     $query->join(['table' => 'pessoas_associacoes', 'alias' => 'PessoasAssociacoes', 'type' => 'INNER', 'conditions' => ['PessoasAssociacoes.pessoa_id = ' . $this->aliasField('pessoa_id'), 'PessoasAssociacoes.tipo_associacao' => 7, 'PessoasAssociacoes.status !=' => 9]]);
     $query->group($this->aliasField('pessoa_id'));
 }