diff -u b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php --- b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -121,10 +121,6 @@ * {@inheritdoc} */ protected function doLoadMultiple(array $ids = NULL) { - if ($ids !== NULL) { - $ids = $this->cleanIds($ids); - } - // Build and execute the query. $records = $this ->buildQuery($ids) @@ -135,30 +131,6 @@ } /** - * Verifies that the specified entity IDs are of the correct data type for the - * entity type. - * - * @param array $ids - * The entity IDs to verify. - * @return array - * The sanitized list of entity IDs. - */ - protected function cleanIds(array $ids) { - $keys = $this->entityType->getKeys(); - $bundle = $keys['bundle'] ? $keys['bundle'] : $this->entityTypeId; - - $definitions = $this->entityManager->getFieldDefinitions($this->entityTypeId, $bundle); - $info = $this->entityManager->getDefinition($this->entityTypeId); - $id_definition = $definitions[$info->getKey('id')]; - - if (!empty($ids) && $id_definition->getType() == 'integer') { - $ids = array_filter($ids, 'is_numeric'); - $ids = array_map('intval', $ids); - } - return $ids; - } - - /** * Maps from storage records to entity objects. * * This will attach fields, if the entity is fieldable. It calls @@ -367,6 +339,10 @@ * {@inheritdoc} */ protected function doLoadMultiple(array $ids = NULL) { + if ($ids !== NULL) { + $ids = $this->cleanIds($ids); + } + // Build and execute the query. $records = $this ->buildQuery($ids) @@ -377,6 +353,43 @@ } /** + * Verifies that the specified entity IDs are of the correct data type for the + * entity type. + * + * The identifier verification provided by this method has been introduced + * as Drupal core used to rely on the database to facilitate this, which worked + * correctly with MySQL but would lead to errors with other DBMS such as + * PostgeSQL. + * + * @param array $ids + * The entity IDs to verify. + * @return array + * The sanitized list of entity IDs. + */ + protected function cleanIds(array $ids) { + $keys = $this->entityType->getKeys(); + $bundle = $keys['bundle'] ? $keys['bundle'] : $this->entityTypeId; + + $definitions = $this->entityManager->getFieldDefinitions($this->entityTypeId, $bundle); + $info = $this->entityManager->getDefinition($this->entityTypeId); + $id_definition = $definitions[$info->getKey('id')]; + + if (!empty($ids)) { + switch ($id_definition->getType()) { + case 'integer': + $ids = array_filter($ids, 'is_numeric'); + $ids = array_map('intval', $ids); + break; + case 'string': + $ids = array_filter($ids, 'is_string'); + $ids = array_map('strval', $ids); + break; + } + } + return $ids; + } + + /** * Maps from storage records to entity objects. * * This will attach fields, if the entity is fieldable. It calls