function Merge::keys

Same name in other branches
  1. 9 core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::keys()
  2. 10 core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::keys()
  3. 11.x core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::keys()

Sets the key fields to be used as conditions for this query.

This method should only be called once. It may be called either with a single associative array or two indexed arrays. If called with an associative array, the keys are taken to be the fields and the values are taken to be the corresponding values to set. If called with two arrays, the first array is taken as the fields and the second array is taken as the corresponding values.

The fields are copied to the condition of the query and the INSERT part. If no other method is called, the UPDATE will become a no-op.

Parameters

$fields: An array of fields to set, or an associative array of fields and values.

$values: An array of values to set into the database. The values must be specified in the same order as the $fields array.

Return value

$this

1 call to Merge::keys()
Merge::key in core/lib/Drupal/Core/Database/Query/Merge.php
Sets a single key field to be used as condition for this query.

File

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

Class

Merge
General class for an abstracted MERGE query operation.

Namespace

Drupal\Core\Database\Query

Code

public function keys(array $fields, array $values = []) {
    if ($values) {
        $fields = array_combine($fields, $values);
    }
    foreach ($fields as $key => $value) {
        $this->insertFields[$key] = $value;
        $this->condition($key, $value);
    }
    return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.