Index: lib/Doctrine/Query.php =================================================================== --- lib/Doctrine/Query.php (revision 7690) +++ lib/Doctrine/Query.php (working copy) @@ -1290,9 +1290,9 @@ // FIX #1868: If not ID under MySQL is found to be restricted, restrict pk column for null // (which will lead to a return of 0 items) - $limitSubquerySql = $this->_conn->quoteIdentifier($field) - . (( ! empty($subquery)) ? ' IN (' . $subquery . ')' : ' IS NULL') - . ((count($this->_sqlParts['where']) > 0) ? ' AND ' : ''); + $limitSubquerySql = ((count($this->_sqlParts['where']) > 0) ? ' AND ' : '') + . $this->_conn->quoteIdentifier($field) + . (( ! empty($subquery)) ? ' IN (' . $subquery . ')' : ' IS NULL'); $modifyLimit = false; } @@ -1305,7 +1305,7 @@ $where = ($where == '' || (substr($where, 0, 1) === '(' && substr($where, -1) === ')')) ? $where : '(' . $where . ')'; - $q .= ' WHERE ' . $limitSubquerySql . $where; + $q .= ' WHERE ' . $where . $limitSubquerySql; // . (($limitSubquerySql == '' && count($this->_sqlParts['where']) == 1) ? substr($where, 1, -1) : $where); }