From 07c29974f14aab1896cbae72e50a7e0c01cd7f3a Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sat, 21 Oct 2017 13:02:58 +0300 Subject: [PATCH] Fixes #12971 Refs: #13124 --- CHANGELOG-3.2.md | 1 + phalcon/mvc/model/query.zep | 2 +- tests/unit/Mvc/Model/QueryTest.php | 47 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-3.2.md b/CHANGELOG-3.2.md index f4510327722..22f77d9773d 100644 --- a/CHANGELOG-3.2.md +++ b/CHANGELOG-3.2.md @@ -1,5 +1,6 @@ # [3.2.4](https://github.com/phalcon/cphalcon/releases/tag/v3.2.4) (2017-21-12) - Fixed regression of [#13046](https://github.com/phalcon/cphalcon/issues/13046) by removing injection of dispatcher's parameters (which were never available anyway) [#13121](https://github.com/phalcon/cphalcon/issues/13121) +- Fixed `Phalcon/Mvc/Model/Query::_getQualified` to correct replace field names in `WHERE` [#12971](https://github.com/phalcon/cphalcon/issues/12971) # [3.2.3](https://github.com/phalcon/cphalcon/releases/tag/v3.2.3) (2017-10-12) - Fixed `Phalcon\Mvc\Model\Query::_executeSelect` threw RuntimeException, if db:beforeQuery() returned false diff --git a/phalcon/mvc/model/query.zep b/phalcon/mvc/model/query.zep index d9c8cef99e9..1526c64de6e 100644 --- a/phalcon/mvc/model/query.zep +++ b/phalcon/mvc/model/query.zep @@ -205,7 +205,7 @@ class Query implements QueryInterface, InjectionAwareInterface * Check if the qualified name is a column alias */ let sqlColumnAliases = this->_sqlColumnAliases; - if isset sqlColumnAliases[columnName] { + if isset sqlColumnAliases[columnName] && empty expr["domain"] { return [ "type": "qualified", "name": columnName diff --git a/tests/unit/Mvc/Model/QueryTest.php b/tests/unit/Mvc/Model/QueryTest.php index fd3843537e7..41132adca41 100644 --- a/tests/unit/Mvc/Model/QueryTest.php +++ b/tests/unit/Mvc/Model/QueryTest.php @@ -6914,7 +6914,54 @@ function ($phql, $expected) { ), ), ) + ], + [ + // PR #13124, ISSUE #12971 + "phql" => 'SELECT UPPER('. Robots::class . '.name) AS name FROM ' . Robots::class . 'WHERE ' . Robots::class .'.name = Robotina', + "expected" => [ + 'distinct' => 0, + 'models' => [ + Robots::class, + ], + 'tables' => [ + 'robots' + ], + 'columns' => [ + 'id' => [ + 'type' => 'scalar', + 'balias' => 'name', + 'sqlAlias' => 'name', + 'column' => [ + 'type' => 'functionCall', + 'name' => 'UPPER', + 'arguments' => [ + [ + 'type' => 'qualified', + 'domain' => 'robots', + 'name' => 'name', + 'balias' => 'name' + ] + ], + ], + ] + ], + 'where' => [ + 'type' => 'binary-op', + 'op' => '=', + 'left' => [ + 'type' => 'qualified', + 'domain' => 'robots', + 'name' => 'name', + 'balias' => 'name' + ], + 'right' => [ + 'type' => 'literal', + 'value' => 'Robotina' + ] + ] + ] ] + ] ] );