lithium\data\source\Database::group()

public method

Return formatted clause for GROUP BY with known fields escaped.

Parameters

  • string|array $group

    The clause to be formatted.

  • object $context

Returns

string|null

Formatted clause, null if there is nothing to format.

Source

	public function group($group, $context) {
		if (!$group) {
			return null;
		}
		$self = $this;
		$model = $context->model();
		$alias = $context->alias();

		$escaped = array_map(function($field) use ($self, $model, $alias) {
			if (!$model || !$model::schema($field)) {
				return $self->name($field);
			}
			return $self->name($alias) . '.' . $self->name($field);
		}, (array) $group);

		return 'GROUP BY ' .  join(', ', $escaped);
	}