How to increment and save an integer value in one operation so that there are no race conditions?
e.g. in mysql
INSERT into mytable (logins) SELECT max(logins) + 1 FROM mytable
Current code is
$query = Drupal::entityQuery('node')->condition('type', 'bond') ->condition('field_para_identifier.entity:paragraph.field_bond_pending_id', 'NULL', 'IS NOT NULL') ->sort('field_para_identifier.entity:paragraph.field_bond_pending_id', 'DESC') ->range(0, 1); $results = $query->execute(); $biggest_pending_id_entity_id = array_pop($results); $next_pending_id = 1; if ($biggest_pending_id) { $next_pending_id = intval($biggest_pending_id) + 1; } $identifier = $bond->get('field_para_identifier')->getValue(); $identifierParagraph = Paragraph::load($identifier[0]['target_id']); $identifierParagraph->set('field_bond_pending_id', $next_pending_id); $identifierParagraph->save();