--- Query.php	2010-08-30 17:21:34.378273000 -0400
+++ lib/doctrine/lib/Doctrine/Query.php	2010-08-30 16:36:34.906273001 -0400
@@ -1325,11 +1325,11 @@
                 $sqlAlias = $this->getSqlTableAlias($alias);
                 if (isset($map['relation'])) {
                     $orderBy = $map['relation']->getOrderByStatement($sqlAlias, true);
-                    if ($map['relation']['orderBy']) {
+                    if ($orderBy == $map['relation']['orderBy']) {
                         if (isset($map['ref'])) {
-                            $orderBy = null;
+                            $orderBy = $map['relation']['refTable']->processOrderBy($sqlAlias, $map['relation']['orderBy'], true);
                         } else {
-                            $orderBy = $map['relation']['table']->processOrderBy($sqlAlias, $map['relation']['orderBy'], true);
+                            $orderBy = null;
                         }
                     }
                 } else {
@@ -2227,4 +2227,4 @@
         $this->_parsers = array();
         $this->_dqlParts = array();
     }
-}
+}
\ No newline at end of file
