Skip to content

Commit

Permalink
Automatically converting SQL functions to the corresponding type
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 1, 2015
1 parent 0485710 commit 375191c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/ORM/Query.php
Expand Up @@ -18,6 +18,7 @@
use Cake\Database\ExpressionInterface;
use Cake\Database\Query as DatabaseQuery;
use Cake\Database\TypeMap;
use Cake\Database\TypedResultInterface;
use Cake\Database\ValueBinder;
use Cake\Datasource\QueryInterface;
use Cake\Datasource\QueryTrait;
Expand Down Expand Up @@ -933,12 +934,16 @@ protected function _addDefaultSelectTypes()
{
$typeMap = $this->typeMap()->defaults();
$selectTypeMap = $this->selectTypeMap();
$select = array_keys($this->clause('select'));
$select = $this->clause('select');
$types = [];

foreach ($select as $alias) {
foreach ($select as $alias => $value) {
if (isset($typeMap[$alias])) {
$types[$alias] = $typeMap[$alias];
continue;
}
if ($value instanceof TypedResultInterface) {
$types[$alias] = $value->returnType();
}
}
$this->selectTypeMap()->addDefaults($types);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -963,9 +963,9 @@ public function testTypemapInFunctions()
]);
$result = $query->all()->first();
$this->assertSame(
'-1',
-1,
$result['coalesced'],
'Output values for functions are not cast yet.'
'Output values for functions should be casted'
);
}

Expand Down

0 comments on commit 375191c

Please sign in to comment.