DDC-2191: Bug in QueryBuilder::add() method, param $append has no effect for where/having DQL parts #2758

Closed
opened 2026-01-22 14:02:38 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 7, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user relo_san:

Now $append param of QueryBuilder::add() method has no effect for where and having parts.

In example:

$query->add('where', 'u.some = ?1');
$query->add('where', 'u.other = ?2', true);

will result in the loss of condition u.some = ?1

Explanation in code
526 line of Doctrine/ORM/QueryBuilder.php, part of body add() method:

if ($append && $isMultiple) {
    if (is_array($dqlPart)) {
        $key = key($dqlPart);
        $this->_dqlParts[$dqlPartName][$key][] = $dqlPart[$key];
    } else {
        $this->_dqlParts[$dqlPartName][] = $dqlPart;
    }
} else {
    $this->_dqlParts[$dqlPartName] = ($isMultiple) ? array($dqlPart) : $dqlPart;
}

According to the code above $append parameter is checked in conjunction with $isMultiple variable, which is:

$isMultiple = is*array($this->*dqlParts[$dqlPartName]);

But in 56 line of this file, class property \*dqlParts keys where and having are equal _null*:

private $_dqlParts = array(
    'distinct' => false,
    'select'  => array(),
    'from'    => array(),
    'join'    => array(),
    'set'     => array(),
    'where'   => null,
    'groupBy' => array(),
    'having'  => null,
    'orderBy' => array()
);

As a result, for the parts where and having condition $append && $isMultiple will never be true, regardless of $append value.

I can offer a patch on Github to fix this bug, if necessary.

Originally created by @doctrinebot on GitHub (Dec 7, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user relo_san: Now `$append` param of `QueryBuilder::add()` method has no effect for `where` and `having` parts. In example: ``` none $query->add('where', 'u.some = ?1'); $query->add('where', 'u.other = ?2', true); ``` will result in the loss of condition `u.some = ?1` **Explanation in code** **526** line of `Doctrine/ORM/QueryBuilder.php`, part of body `add()` method: ``` none if ($append && $isMultiple) { if (is_array($dqlPart)) { $key = key($dqlPart); $this->_dqlParts[$dqlPartName][$key][] = $dqlPart[$key]; } else { $this->_dqlParts[$dqlPartName][] = $dqlPart; } } else { $this->_dqlParts[$dqlPartName] = ($isMultiple) ? array($dqlPart) : $dqlPart; } ``` According to the code above `$append` parameter is checked in conjunction with `$isMultiple` variable, which is: ``` none $isMultiple = is*array($this->*dqlParts[$dqlPartName]); ``` But in **56** line of this file, class property `\*dqlParts` keys `where` and `having` are equal _null*: ``` none private $_dqlParts = array( 'distinct' => false, 'select' => array(), 'from' => array(), 'join' => array(), 'set' => array(), 'where' => null, 'groupBy' => array(), 'having' => null, 'orderBy' => array() ); ``` As a result, for the parts `where` and `having` condition **$append && $isMultiple** will never be true, regardless of `$append` value. I can offer a patch on Github to fix this bug, if necessary.
admin added the Bug label 2026-01-22 14:02:38 +01:00
admin closed this issue 2026-01-22 14:02:39 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 6, 2013):

Comment created by @beberlei:

This was and will never be allowed, i introduced an exception to show a way out, you need to look at QueryBuilder#andWhere for example to see a solution to append to where clauses.

@doctrinebot commented on GitHub (Jan 6, 2013): Comment created by @beberlei: This was and will never be allowed, i introduced an exception to show a way out, you need to look at QueryBuilder#andWhere for example to see a solution to append to where clauses.
Author
Owner

@doctrinebot commented on GitHub (Jan 6, 2013):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jan 6, 2013): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2758