Index: Doctrine/Query.php =================================================================== --- Doctrine/Query.php (revision 6681) +++ Doctrine/Query.php (working copy) @@ -1281,31 +1281,36 @@ // . (($limitSubquerySql == '' && count($this->_sqlParts['where']) == 1) ? substr($where, 1, -1) : $where); } - // Fix the orderbys so we only have one orderby per value - foreach ($this->_sqlParts['orderby'] as $k => $orderBy) { - $e = explode(', ', $orderBy); - unset($this->_sqlParts['orderby'][$k]); - foreach ($e as $v) { - $this->_sqlParts['orderby'][] = $v; - } - } + // orderby only if it is a select query, otherwise + // you get aliases on UPDATE and DELETE which do not support them + if ($this->_type === self::SELECT) { - // Add the default orderBy statements defined in the relationships and table classes - $added = array(); - foreach ($this->_queryComponents as $alias => $map) { - $sqlAlias = $this->getSqlTableAlias($alias); - if (isset($map['relation'])) { - $orderBy = $map['relation']->getOrderByStatement($sqlAlias, true); - } else { - $orderBy = $map['table']->getOrderByStatement($sqlAlias, true); + // Fix the orderbys so we only have one orderby per value + foreach ($this->_sqlParts['orderby'] as $k => $orderBy) { + $e = explode(', ', $orderBy); + unset($this->_sqlParts['orderby'][$k]); + foreach ($e as $v) { + $this->_sqlParts['orderby'][] = $v; + } } - if ($orderBy) { - $e = explode(',', $orderBy); - $e = array_map('trim', $e); - foreach ($e as $v) { - if ( ! in_array($v, $this->_sqlParts['orderby'])) { - $this->_sqlParts['orderby'][] = $v; + // Add the default orderBy statements defined in the relationships and table classes + $added = array(); + foreach ($this->_queryComponents as $alias => $map) { + $sqlAlias = $this->getSqlTableAlias($alias); + if (isset($map['relation'])) { + $orderBy = $map['relation']->getOrderByStatement($sqlAlias, true); + } else { + $orderBy = $map['table']->getOrderByStatement($sqlAlias, true); + } + + if ($orderBy) { + $e = explode(',', $orderBy); + $e = array_map('trim', $e); + foreach ($e as $v) { + if ( ! in_array($v, $this->_sqlParts['orderby'])) { + $this->_sqlParts['orderby'][] = $v; + } } } }