Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::key()
  2. 9 core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::key()

Sets a single key field to be used as condition for this query.

Same as \Drupal\Core\Database\Query\Merge::keys() but offering a signature that is more natural for the case of a single key.

Parameters

string $field: The name of the field to set.

mixed $value: The value to set into the database.

Return value

$this

See also

\Drupal\Core\Database\Query\Merge::keys()

File

core/lib/Drupal/Core/Database/Query/Merge.php, line 333

Class

Merge
General class for an abstracted MERGE query operation.

Namespace

Drupal\Core\Database\Query

Code

public function key($field, $value = NULL) {

  // @todo D9: Remove this backwards-compatibility shim.
  if (is_array($field)) {
    @trigger_error("Passing an array to the \$field argument of " . __METHOD__ . '() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/2205327', E_USER_DEPRECATED);
    $this
      ->keys($field, $value ?? []);
  }
  else {
    $this
      ->keys([
      $field => $value,
    ]);
  }
  return $this;
}