diff --git a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php index caadc37..479fbac 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php @@ -52,6 +52,17 @@ public function getEntityTypeId(); * "tags" "is the same as "tags.value" as value is the default column. * If two or more conditions have the same field names they apply to the * same delta within that field. + * It is also possible to add the numeric delta value between the field + * name and the column name, for example tags.5.value. + * Finally, it's possible to create a condition on delta itself by using a + * ? as a wildcard. For example, ->condition('tags.?', 5) will find only + * entities which have at least six tags. Also, tags.? within a condition + * group means a specific delta so + * @code + * ->condition('tags.?', 0, '>')) + * ->condition('tags.?.value', 'foo')) + * @endcode + * will only find the "foo" tag if it is not the first tag. * @param $value * The value for $field. In most cases, this is a scalar and it's treated as * case-insensitive. For more complex options, it is an array. The meaning diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index e0fbe85..4c214f0 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -125,15 +125,17 @@ public function addField($field, $type, $langcode) { } // Is this a delta wildcard? elseif ($next == '?') { - $index_prefix .= ".$delta"; + $index_prefix .= '.?'; // Do not process it again. $key++; - // Is this a real condition with a wildcard? + // If there are yet specifiers to work with then continue + // processing. If this is the last specifier then use the delta + // wildcard as column name. if ($key < $count) { $next = $specifiers[$key + 1]; } else { - $column = $next; + $column = '?'; } } // Is this a field column? diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php b/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php index ac6d986..13745a4 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/TablesInterface.php @@ -16,8 +16,10 @@ * Adds a field to a database query. * * @param string $field - * If it contains a dot, then field name dot field column or field name dot - * delta dot field column. If it doesn't then entity property name. + * If it doesn't contain a dot, then an entity base field name. + * If it contains a dot, then either field name dot field column or + * field name dot delta dot field column. Delta can be a numeric value or a + * ? for any value. * @param string $type * Join type, can either be INNER or LEFT. * @param $langcode