Cake\Database\Query::group PHP Метод

group() публичный Метод

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
    public function group($fields, $overwrite = false)
    {
        if ($overwrite) {
            $this->_parts['group'] = [];
        }
        if (!is_array($fields)) {
            $fields = [$fields];
        }
        $this->_parts['group'] = array_merge($this->_parts['group'], array_values($fields));
        $this->_dirty();
        return $this;
    }

Usage 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;
 }
All Usage Examples Of Cake\Database\Query::group