Loading core/lib/Drupal/Core/Entity/Query/Sql/Condition.php +1 −1 Changes for core/lib/Drupal/Core/Entity/Query/Sql/Condition.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ public function compile($conditionContainer) { // use condition groups to fetch where a entity has X AND Y. // If we did not join the table again, the values only exist once // and the AND fails to match even though an entity has both X and Y. $condition['field']->tableIndexPrefix = $this->conjunction === 'AND' ? $this->tableIndexPrefix . '.' . $key : $this->tableIndexPrefix; $condition['field']->tableIndexPrefix = strtoupper($this->conjunction) === 'AND' ? $this->tableIndexPrefix . '.' . $key : $this->tableIndexPrefix; $condition['field']->nestedInsideOrCondition = $this->nestedInsideOrCondition || strtoupper($this->conjunction) === 'OR'; $condition['field']->compile($sql_condition); $conditionContainer->condition($sql_condition); Loading core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php +26 −0 Changes for core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php: 26 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -745,6 +745,32 @@ public function testNestedConditionGroups(): void { $this->assertResult(4, 6, 12, 14); } /** * Tests an AND group of OR groups on a multi-value field. */ public function testAndGroupOfOrGroupsOnMultiValueField(): void { foreach ([$this->figures, $this->figuresUnlimited] as $field_name) { $query = $this->storage->getQuery()->accessCheck(FALSE); $red_or_square = $query->orConditionGroup() ->condition("$field_name.color", 'red') ->condition("$field_name.shape", 'square'); $blue_or_hexagon = $query->orConditionGroup() ->condition("$field_name.color", 'blue') ->condition("$field_name.shape", 'hexagon'); $and = $query->andConditionGroup() ->condition($red_or_square) ->condition($blue_or_hexagon); $this->queryResults = $query ->condition($and) ->sort('revision_id') ->execute(); // Only entities that match both OR groups should be found. $this->assertResult(3, 7, 11, 15); } } /** * Tests that condition count returns expected number of conditions. */ Loading Loading
core/lib/Drupal/Core/Entity/Query/Sql/Condition.php +1 −1 Changes for core/lib/Drupal/Core/Entity/Query/Sql/Condition.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ public function compile($conditionContainer) { // use condition groups to fetch where a entity has X AND Y. // If we did not join the table again, the values only exist once // and the AND fails to match even though an entity has both X and Y. $condition['field']->tableIndexPrefix = $this->conjunction === 'AND' ? $this->tableIndexPrefix . '.' . $key : $this->tableIndexPrefix; $condition['field']->tableIndexPrefix = strtoupper($this->conjunction) === 'AND' ? $this->tableIndexPrefix . '.' . $key : $this->tableIndexPrefix; $condition['field']->nestedInsideOrCondition = $this->nestedInsideOrCondition || strtoupper($this->conjunction) === 'OR'; $condition['field']->compile($sql_condition); $conditionContainer->condition($sql_condition); Loading
core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php +26 −0 Changes for core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php: 26 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -745,6 +745,32 @@ public function testNestedConditionGroups(): void { $this->assertResult(4, 6, 12, 14); } /** * Tests an AND group of OR groups on a multi-value field. */ public function testAndGroupOfOrGroupsOnMultiValueField(): void { foreach ([$this->figures, $this->figuresUnlimited] as $field_name) { $query = $this->storage->getQuery()->accessCheck(FALSE); $red_or_square = $query->orConditionGroup() ->condition("$field_name.color", 'red') ->condition("$field_name.shape", 'square'); $blue_or_hexagon = $query->orConditionGroup() ->condition("$field_name.color", 'blue') ->condition("$field_name.shape", 'hexagon'); $and = $query->andConditionGroup() ->condition($red_or_square) ->condition($blue_or_hexagon); $this->queryResults = $query ->condition($and) ->sort('revision_id') ->execute(); // Only entities that match both OR groups should be found. $this->assertResult(3, 7, 11, 15); } } /** * Tests that condition count returns expected number of conditions. */ Loading