W3cubDocs

/Drupal 8

public function Select::fields

public Select::fields($table_alias, array $fields = array())

Add multiple fields from the same table to be SELECTed.

This method does not return the aliases set for the passed fields. In the majority of cases that is not a problem, as the alias will be the field name. However, if you do need to know the alias you can call getFields() and examine the result to determine what alias was created. Alternatively, simply use addField() for the few fields you care about and this method for the rest.

Parameters

$table_alias: The name of the table from which the field comes, as an alias. Generally you will want to use the return value of join() here to ensure that it is valid.

$fields: An indexed array of fields present in the specified table that should be included in this query. If not specified, $table_alias.* will be generated without any aliases.

Return value

\Drupal\Core\Database\Query\SelectInterface The called object.

Overrides SelectInterface::fields

File

core/lib/Drupal/Core/Database/Query/Select.php, line 538

Class

Select
Query builder for SELECT statements.

Namespace

Drupal\Core\Database\Query

Code

public function fields($table_alias, array $fields = array()) {
  if ($fields) {
    foreach ($fields as $field) {
      // We don't care what alias was assigned.
      $this->addField($table_alias, $field);
    }
  }
  else {
    // We want all fields from this table.
    $this->tables[$table_alias]['all_fields'] = TRUE;
  }

  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Query!Select.php/function/Select::fields/8.1.x