Browse Source

Merge pull request #7881 from cakephp/fix-sql-server

Fix SQLServer
Mark Story 10 years ago
parent
commit
a32e327d65
2 changed files with 13 additions and 4 deletions
  1. 5 2
      src/ORM/EagerLoader.php
  2. 8 2
      tests/TestCase/ORM/QueryRegressionTest.php

+ 5 - 2
src/ORM/EagerLoader.php

@@ -136,7 +136,8 @@ class EagerLoader
 
         $associations = (array)$associations;
         $associations = $this->_reformatContain($associations, $this->_containments);
-        $this->_normalized = $this->_loadExternal = null;
+        $this->_normalized = null;
+        $this->_loadExternal = [];
         $this->_aliasList = [];
         return $this->_containments = $associations;
     }
@@ -152,7 +153,8 @@ class EagerLoader
     public function clearContain()
     {
         $this->_containments = [];
-        $this->_normalized = $this->_loadExternal = null;
+        $this->_normalized = null;
+        $this->_loadExternal = [];
         $this->_aliasList = [];
     }
 
@@ -366,6 +368,7 @@ class EagerLoader
         $contain = $this->normalized($repository);
         $matching = $this->_matching ? $this->_matching->normalized($repository) : [];
         $this->_fixStrategies();
+        $this->_loadExternal = [];
         return $this->_resolveJoins($contain, $matching);
     }
 

+ 8 - 2
tests/TestCase/ORM/QueryRegressionTest.php

@@ -1217,7 +1217,10 @@ class QueryRegressionTest extends TestCase
     {
         $table = TableRegistry::get('Articles');
         $query = $table->find();
-        $query->orderDesc($query->newExpr()->add(['id' => 3]));
+        $query->orderDesc($query->newExpr()->addCase(
+            [$query->newExpr()->add(['id' => 3])],
+            [1, 0]
+        ));
         $query->order(['title' => 'desc']);
         // Executing the normal query before getting the count
         $query->all();
@@ -1225,8 +1228,11 @@ class QueryRegressionTest extends TestCase
 
         $table = TableRegistry::get('Articles');
         $query = $table->find();
+        $query->orderDesc($query->newExpr()->addCase(
+            [$query->newExpr()->add(['id' => 3])],
+            [1, 0]
+        ));
         $query->orderDesc($query->newExpr()->add(['id' => 3]));
-        $query->order(['title' => 'desc']);
         // Not executing the query first, just getting the count
         $this->assertEquals(3, $query->count());
     }