Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore result columns when calling a aggregate function #120

Merged
merged 1 commit into from
Aug 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,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