From f80c2ea2cdbab7a1a74d5cccc0c82144e586faa7 Mon Sep 17 00:00:00 2001 From: dreamszhu Date: Sat, 18 Mar 2017 18:12:36 +0800 Subject: [PATCH] Fix bug #12715 --- CHANGELOG.md | 1 + phalcon/mvc/model/query.zep | 10 +++++----- unit-tests/ModelsQueryExecuteTest.php | 8 ++++++++ unit-tests/models/Robots2.php | 26 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 unit-tests/models/Robots2.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ba55fd6d1c..6cd3990a924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Fixed `Phalcon\Mvc\Model` to correctly add error when try to save empty string value to not null and not default column [#12688](https://github.com/phalcon/cphalcon/issues/12688) - Fixed `Phalcon\Validation\Validator\Uniqueness` collection persistent condition - Fixed `Phalcon\Loader::autoLoad` to prevent PHP warning [#12684](https://github.com/phalcon/cphalcon/pull/12684) +- Fixed `Phalcon\Mvc\Model\Query::_executeSelect` to correctly get the column map [#12715](https://github.com/phalcon/cphalcon/issues/12715) # [3.0.4](https://github.com/phalcon/cphalcon/releases/tag/v3.0.4) (2017-02-20) - Fixed Isnull check is not correct when the model field defaults to an empty string. [#12507](https://github.com/phalcon/cphalcon/issues/12507) diff --git a/phalcon/mvc/model/query.zep b/phalcon/mvc/model/query.zep index 05e9e1d8f6d..32725c71ee9 100644 --- a/phalcon/mvc/model/query.zep +++ b/phalcon/mvc/model/query.zep @@ -2799,15 +2799,15 @@ class Query implements QueryInterface, InjectionAwareInterface * Get the column map */ if !globals_get("orm.cast_on_hydrate") { - let simpleColumnMap = metaData->getColumnMap(model); + let simpleColumnMap = metaData->getColumnMap(resultObject); } else { - let columnMap = metaData->getColumnMap(model), - typesColumnMap = metaData->getDataTypes(model); + let columnMap = metaData->getColumnMap(resultObject), + typesColumnMap = metaData->getDataTypes(resultObject); if typeof columnMap === "null" { let simpleColumnMap = []; - for attribute in metaData->getAttributes(model) { + for attribute in metaData->getAttributes(resultObject) { let simpleColumnMap[attribute] = [attribute, typesColumnMap[attribute]]; } } else { @@ -2821,7 +2821,7 @@ class Query implements QueryInterface, InjectionAwareInterface /** * Check if the model keeps snapshots */ - let isKeepingSnapshots = (boolean) manager->isKeepingSnapshots(model); + let isKeepingSnapshots = (boolean) manager->isKeepingSnapshots(resultObject); } if resultObject instanceof ModelInterface && method_exists(resultObject, "getResultsetClass") { diff --git a/unit-tests/ModelsQueryExecuteTest.php b/unit-tests/ModelsQueryExecuteTest.php index fca2ba35287..61728f6447a 100644 --- a/unit-tests/ModelsQueryExecuteTest.php +++ b/unit-tests/ModelsQueryExecuteTest.php @@ -699,6 +699,14 @@ public function _testSelectRenamedExecute($di) $this->assertEquals($result[1]->r->code, 1); $this->assertEquals($result[1]->p->code, 2); + $result = $manager->executeQuery( + 'SELECT r.* FROM RobotsParts rp LEFT JOIN Robots2 r ON rp.robots_id=r.id' + ); + $this->assertInstanceOf('Phalcon\Mvc\Model\Resultset\Simple', $result); + $this->assertEquals(gettype($result[0]), 'object'); + $this->assertEquals(get_class($result[0]), 'Robots2'); + $this->assertNotNull($result[0]->getName()); + $result = $manager->executeQuery( 'SELECT r.* FROM Robots r WHERE r.id NOT IN (SELECT p.id FROM Parts p WHERE r.id < p.id)' ); diff --git a/unit-tests/models/Robots2.php b/unit-tests/models/Robots2.php new file mode 100644 index 00000000000..b3b48795774 --- /dev/null +++ b/unit-tests/models/Robots2.php @@ -0,0 +1,26 @@ +myname; + } + + public function columnMap() { + return array( + 'id' => 'id', + 'name' => 'myname', + 'type' => 'type', + 'year' => 'year', + 'datetime' => 'datetime', + 'deleted' => 'deleted', + 'text' => 'text', + ); + } +}