From 375191ce875af649a228826dc7d697fc3d64a920 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 1 Dec 2015 22:47:05 +0100 Subject: [PATCH] Automatically converting SQL functions to the corresponding type --- src/ORM/Query.php | 9 +++++++-- tests/TestCase/ORM/QueryRegressionTest.php | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ORM/Query.php b/src/ORM/Query.php index 76f3080c449..5ef298496b8 100644 --- a/src/ORM/Query.php +++ b/src/ORM/Query.php @@ -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; @@ -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); diff --git a/tests/TestCase/ORM/QueryRegressionTest.php b/tests/TestCase/ORM/QueryRegressionTest.php index 19c14d0ca0e..0dddd500f7b 100644 --- a/tests/TestCase/ORM/QueryRegressionTest.php +++ b/tests/TestCase/ORM/QueryRegressionTest.php @@ -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' ); }