From 5c93e616869ecf54baf1a897b8b02c6d607fdcca Mon Sep 17 00:00:00 2001
From: Bill Schaller <bill@zeroedin.com>
Date: Tue, 31 Mar 2015 13:59:24 -0400
Subject: [PATCH] Fix issue in LimitSubqueryOutputWalker with entities having
 field names different from column names

---
 .../ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
index 71123aa39..3103b4248 100644
--- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
+++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
@@ -410,27 +410,27 @@ class LimitSubqueryOutputWalker extends SqlWalker
         $fieldSearchPattern = '/(?<![a-z0-9_])%s\.%s(?![a-z0-9_])/i';
 
         // Generate search patterns for each field's path expression in the order by clause
-        foreach($this->rsm->fieldMappings as $fieldAlias => $columnName) {
+        foreach($this->rsm->fieldMappings as $fieldAlias => $fieldName) {
             $dqlAliasForFieldAlias = $this->rsm->columnOwnerMap[$fieldAlias];
             $class = $dqlAliasToClassMap[$dqlAliasForFieldAlias];
 
             // If the field is from a joined child table, we won't be ordering
             // on it.
-            if (!isset($class->fieldMappings[$columnName])) {
+            if (!isset($class->fieldMappings[$fieldName])) {
                 continue;
             }
 
+            $fieldMapping = $class->fieldMappings[$fieldName];
+
             // Get the proper column name as will appear in the select list
             $columnName = $this->quoteStrategy->getColumnName(
-                $columnName,
+                $fieldName,
                 $dqlAliasToClassMap[$dqlAliasForFieldAlias],
                 $this->em->getConnection()->getDatabasePlatform()
             );
 
             // Get the SQL table alias for the entity and field
             $sqlTableAliasForFieldAlias = $dqlAliasToSqlTableAliasMap[$dqlAliasForFieldAlias];
-
-            $fieldMapping = $class->fieldMappings[$columnName];
             if (isset($fieldMapping['declared']) && $fieldMapping['declared'] !== $class->name) {
                 // Field was declared in a parent class, so we need to get the proper SQL table alias
                 // for the joined parent table.