summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancesco Placella2018-05-17 15:12:38 (GMT)
committerFrancesco Placella2018-05-17 15:12:38 (GMT)
commite551206954fe8ed16c9b0894c0cd17beeaf4335d (patch)
treedacd34c4f06a9ec1dd3e967c6d6958de514d6b46
parent593ded04f355ff2610cf4205d7dd7fc18ea23603 (diff)
Issue #2580265 by FeyP, jcisio, s_leu, Berdir, tstoeckler: entity query nested conditions must use LEFT joins when any of the parent condition groups is using OR
-rw-r--r--core/lib/Drupal/Core/Entity/Query/Sql/Condition.php10
-rw-r--r--core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php2
2 files changed, 10 insertions, 2 deletions
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
index 00fe78c..7f93512 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
@@ -13,6 +13,13 @@ use Drupal\Core\Entity\Query\ConditionInterface;
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.
*
* @var \Drupal\Core\Entity\Query\Sql\Query
@@ -36,11 +43,12 @@ class Condition extends ConditionBase {
$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 88bdf50..2c9b868 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php
@@ -553,7 +553,7 @@ class EntityQueryTest extends EntityKernelTestBase {
->sort('id')
->execute();
- $this->assertResult(6, 14);
+ $this->assertResult(4, 6, 12, 14);
}
/**