From d1a02c523a468a021b20d417be8bb1bd38755248 Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Wed, 8 May 2013 02:13:26 -0300 Subject: Ignore result columns when calling a aggregate function --- idiorm.php | 3 +++ test/QueryBuilderTest.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/idiorm.php b/idiorm.php index 5b327a6..e1132d3 100644 --- a/idiorm.php +++ b/idiorm.php @@ -616,8 +616,11 @@ if('*' != $column) { $column = $this->_quote_identifier($column); } + $result_columns = $this->_result_columns; + $this->_result_columns = array(); $this->select_expr("$sql_function($column)", $alias); $result = $this->find_one(); + $this->_result_columns = $result_columns; $return_value = 0; if($result !== false && isset($result->$alias)) { diff --git a/test/QueryBuilderTest.php b/test/QueryBuilderTest.php index bd888c0..6888c85 100644 --- a/test/QueryBuilderTest.php +++ b/test/QueryBuilderTest.php @@ -477,6 +477,12 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase { $expected = "SELECT COUNT(*) AS `count` FROM `widget` LIMIT 1"; $this->assertEquals($expected, ORM::get_last_query()); } + + public function testIgnoreSelectAndCount() { + ORM::for_table('widget')->select('test')->count(); + $expected = "SELECT COUNT(*) AS `count` FROM `widget` LIMIT 1"; + $this->assertEquals($expected, ORM::get_last_query()); + } public function testMax() { ORM::for_table('person')->max('height'); -- cgit v1.2.3