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
parent
593ded04f3
commit
e551206954
|
@ -12,6 +12,13 @@ use Drupal\Core\Entity\Query\ConditionInterface;
|
||||||
*/
|
*/
|
||||||
class Condition extends ConditionBase {
|
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.
|
* The SQL entity query object this condition belongs to.
|
||||||
*
|
*
|
||||||
|
@ -36,11 +43,12 @@ class Condition extends ConditionBase {
|
||||||
$sql_condition = new SqlCondition($condition['field']->getConjunction());
|
$sql_condition = new SqlCondition($condition['field']->getConjunction());
|
||||||
// Add the SQL query to the object before calling this method again.
|
// Add the SQL query to the object before calling this method again.
|
||||||
$sql_condition->sqlQuery = $sql_query;
|
$sql_condition->sqlQuery = $sql_query;
|
||||||
|
$condition['field']->nestedInsideOrCondition = $this->nestedInsideOrCondition || strtoupper($this->conjunction) === 'OR';
|
||||||
$condition['field']->compile($sql_condition);
|
$condition['field']->compile($sql_condition);
|
||||||
$conditionContainer->condition($sql_condition);
|
$conditionContainer->condition($sql_condition);
|
||||||
}
|
}
|
||||||
else {
|
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']);
|
$field = $tables->addField($condition['field'], $type, $condition['langcode']);
|
||||||
$condition['real_field'] = $field;
|
$condition['real_field'] = $field;
|
||||||
static::translateCondition($condition, $sql_query, $tables->isFieldCaseSensitive($condition['field']));
|
static::translateCondition($condition, $sql_query, $tables->isFieldCaseSensitive($condition['field']));
|
||||||
|
|
|
@ -553,7 +553,7 @@ class EntityQueryTest extends EntityKernelTestBase {
|
||||||
->sort('id')
|
->sort('id')
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$this->assertResult(6, 14);
|
$this->assertResult(4, 6, 12, 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue