Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By sun on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0-alpha10
Description:
- The
Drupal\Core\Database\Merge::key()
method has been renamed toMerge::keys()
. - The
Drupal\Core\Database\Merge::key()
method accepts a single pair of key and value now.
Drupal 10 update
Beginning with Drupal 10.2, the use of Merge::key()
with an array of multiple values will cause a deprecation warning.
Drupal 7
// Single primary key.
db_merge('mytable_single_primary_key')
->key(array('id' => $id))
->fields(array('title' => $title))
->execute();
// Multiple/composite primary key.
db_merge('mytable_multiple_primary_key')
->key(array(
'id' => $id,
'vid' => $vid,
))
->fields(array('title' => $title))
->execute();
Drupal 8
// Single primary key.
Database::getConnection()->merge('mytable_single_primary_key')
// First argument is the key name, second is the value.
->key('id', $id)
->fields(array('title' => $title))
->execute();
// Multiple/composite primary key.
Database::getConnection()->merge('mytable_multiple_primary_key')
// Identical to key() previously, just plural now.
->keys(array(
'id' => $id,
'vid' => $vid,
))
->fields(array('title' => $title))
->execute();
Impacts:
Module developers