Skip to content

Commit

Permalink
Merge pull request #120 from tassoevan/develop
Browse files Browse the repository at this point in the history
Ignore result columns when calling a aggregate function
  • Loading branch information
treffynnon committed Aug 28, 2013
2 parents 2a3758e + d1a02c5 commit b1d868a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,11 @@ protected function _call_aggregate_db_function($sql_function, $column) {
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)) {
Expand Down
6 changes: 6 additions & 0 deletions test/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ public function testCount() {
$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');
Expand Down

0 comments on commit b1d868a

Please sign in to comment.