diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php index 00fe78c27f3d9c689d702d8e248f1d21897b00f2..7f9351214d1e1474d146d4fe61007a326a12c105 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php @@ -12,6 +12,13 @@ */ class Condition extends ConditionBase { + /** + * Whether this condition is nested inside an OR condition. + * + * @var bool + */ + protected $nestedInsideOrCondition = FALSE; + /** * The SQL entity query object this condition belongs to. * @@ -36,11 +43,12 @@ public function compile($conditionContainer) { $sql_condition = new SqlCondition($condition['field']->getConjunction()); // Add the SQL query to the object before calling this method again. $sql_condition->sqlQuery = $sql_query; + $condition['field']->nestedInsideOrCondition = $this->nestedInsideOrCondition || strtoupper($this->conjunction) === 'OR'; $condition['field']->compile($sql_condition); $conditionContainer->condition($sql_condition); } else { - $type = strtoupper($this->conjunction) == 'OR' || $condition['operator'] == 'IS NULL' ? 'LEFT' : 'INNER'; + $type = $this->nestedInsideOrCondition || strtoupper($this->conjunction) === 'OR' || $condition['operator'] === 'IS NULL' ? 'LEFT' : 'INNER'; $field = $tables->addField($condition['field'], $type, $condition['langcode']); $condition['real_field'] = $field; static::translateCondition($condition, $sql_query, $tables->isFieldCaseSensitive($condition['field'])); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php index 88bdf50a7403868e105cd85972aeacbffef684c8..2c9b86826d761f1a283237022199edc966f076bc 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php @@ -553,7 +553,7 @@ public function testNestedConditionGroups() { ->sort('id') ->execute(); - $this->assertResult(6, 14); + $this->assertResult(4, 6, 12, 14); } /**