public function Merge::fields in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::fields()
- 9 core/lib/Drupal/Core/Database/Query/Merge.php \Drupal\Core\Database\Query\Merge::fields()
Sets common field-value pairs in the INSERT and UPDATE query parts.
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.
Parameters
$fields: An array of fields to insert, or an associative array of fields and values. The keys of the array are taken to be the fields and the values are taken to be corresponding values to insert.
$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 The called object.
File
- core/
lib/ Drupal/ Core/ Database/ Query/ Merge.php, line 274
Class
- Merge
- General class for an abstracted MERGE query operation.
Namespace
Drupal\Core\Database\QueryCode
public function fields(array $fields, array $values = []) {
if ($values) {
$fields = array_combine($fields, $values);
}
foreach ($fields as $key => $value) {
$this->insertFields[$key] = $value;
$this->updateFields[$key] = $value;
}
$this->needsUpdate = TRUE;
return $this;
}