From f48b908ac6273cf7b188e754639192fcc3e2a175 Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 25 Mar 2007 18:17:15 +0000 Subject: [PATCH] Disabling ORDER BY clause for Model::findCount (Ticket #2227) and updating test case git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4677 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 4 ++-- cake/libs/router.php | 1 - cake/tests/cases/libs/model/model.test.php | 25 ++++++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index bc992ceb5..8b52a31b6 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1386,7 +1386,7 @@ class Model extends Overloadable { $offset = ($page - 1) * $limit; } - if ($order == null) { + if ($order == null && $order !== false) { if ($this->order == null) { $order = array(); } else { @@ -1495,7 +1495,7 @@ class Model extends Overloadable { * @see Model::findAll */ function findCount($conditions = null, $recursive = 0) { - list($data) = $this->findAll($conditions, 'COUNT(*) AS count', $this->escapeField(), null, 1, $recursive); + list($data) = $this->findAll($conditions, 'COUNT(*) AS count', false, null, 1, $recursive); if (isset($data[0]['count'])) { return $data[0]['count']; diff --git a/cake/libs/router.php b/cake/libs/router.php index 79e3bdafa..bf913078a 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -768,7 +768,6 @@ class Router extends Object { */ if(!function_exists('http_build_query')) { function http_build_query($data, $prefix = null, $argSep = null, $baseKey = null) { - //die('?'); if(empty($argSep)) { $argSep = ini_get('arg_separator.output'); } diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 1ee6df746..5a0fa8647 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -383,14 +383,25 @@ class ModelTest extends CakeTestCase { )) ); $this->assertEqual($result, $expected); - - /* - $result = $this->model->hasMany; - $expected = array(); - $this->assertEqual($result, $expected); - */ } - + + function testFindCount() { + $this->model =& new User(); + $result = $this->model->findCount(); + $this->assertEqual($result, 4); + + $this->db->fullDebug = true; + $this->model->order = 'User.id'; + $result = $this->model->findCount(); + $this->assertEqual($result, 4); + + $this->assertTrue(isset($this->db->_queriesLog[0]['query'])); + $this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']); + + $this->db->_queriesLog = array(); + $this->db->fullDebug = false; + } + function testFindMagic() { $this->model =& new User();