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

protected method

Renders the fields SQL fragment for queries.

Parameters

  • string $type

    Type of query i.e. 'create' or 'update'.

  • object $context

    Generally a data\model\Query instance.

  • array $fields
  • array $schema

    An array defining the schema of the fields used in the criteria.

Returns

string|array|null

Source

	protected function _fieldsReturn($type, $context, $fields, $schema) {
		if ($type === 'create' || $type === 'update') {
			$data = $context->data();

			if (isset($data['data']) && is_array($data['data']) && count($data) === 1) {
				$data = $data['data'];
			}
			if ($fields && is_array($fields) && is_int(key($fields))) {
				$data = array_intersect_key($data, array_combine($fields, $fields));
			}
			$method = "_{$type}Fields";
			return $this->{$method}($data, $schema, $context);
		}
		return empty($fields) ? '*' : join(', ', $fields);
	}