diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index 956fa17..d4480b7 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -5,6 +5,7 @@ use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; +use Drupal\Core\Entity\Sql\TableMappingInterface; /** * Adds tables and fields to the SQL entity query. @@ -136,7 +137,7 @@ public function addField($field, $type, $langcode) { $next = $specifiers[$key + 1]; } else { - $column = '_delta'; + $column = TableMappingInterface::DELTA; } } // Is this a field column? diff --git a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php index 170c6ea..7e34b84 100644 --- a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php +++ b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php @@ -203,7 +203,7 @@ public function getFieldColumnName(FieldStorageDefinitionInterface $storage_defi $column_name = count($storage_definition->getColumns()) == 1 ? $field_name : $field_name . '__' . $property_name; } elseif ($this->requiresDedicatedTableStorage($storage_definition)) { - if ($property_name == '_delta') { + if ($property_name == TableMappingInterface::DELTA) { $column_name = 'delta'; } else { diff --git a/core/lib/Drupal/Core/Entity/Sql/TableMappingInterface.php b/core/lib/Drupal/Core/Entity/Sql/TableMappingInterface.php index f21c270..f4f6f09 100644 --- a/core/lib/Drupal/Core/Entity/Sql/TableMappingInterface.php +++ b/core/lib/Drupal/Core/Entity/Sql/TableMappingInterface.php @@ -20,6 +20,11 @@ interface TableMappingInterface { /** + * A property that represents delta used in entity query conditions. + */ + const DELTA = '*delta'; + + /** * Gets a list of table names for this mapping. * * @return string[] diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php index 095d25b..4a6c580 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php @@ -532,6 +532,17 @@ public function testDelta() { // Delta 1 is not red. $this->assertResult(); + // Test on two different deltas. + $query = $this->factory->get('entity_test_mulrev'); + $or = $query->andConditionGroup() + ->condition("$figures.0.color", 'red') + ->condition("$figures.1.color", 'blue'); + $this->queryResults = $query + ->condition($or) + ->sort('id') + ->execute(); + $this->assertResult(3, 7, 11, 15); + // Test '*' wildcard. $this->queryResults = $this->factory->get('entity_test_mulrev') ->condition("$figures.*.color", array('blue', 'red'), 'IN')