Skip to content

Commit

Permalink
Merge pull request #12719 from dreamsxin/12715
Browse files Browse the repository at this point in the history
Fix bug #12715
  • Loading branch information
sergeyklay authored Mar 18, 2017
2 parents 0d89a9e + 1ae8244 commit a1e2ed7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- Fixed params view scope for PHP5 [#12648](https://github.com/phalcon/cphalcon/issues/12648)

# [3.0.4](https://github.com/phalcon/cphalcon/releases/tag/v3.0.4) (2017-02-20)
Expand Down
10 changes: 5 additions & 5 deletions phalcon/mvc/model/query.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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") {
Expand Down
8 changes: 8 additions & 0 deletions unit-tests/ModelsQueryExecuteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
);
Expand Down
26 changes: 26 additions & 0 deletions unit-tests/models/Robots2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

class Robots2 extends Phalcon\Mvc\Model
{
protected $myname;

public function getSource() {
return 'robots';
}

public function getName() {
return $this->myname;
}

public function columnMap() {
return array(
'id' => 'id',
'name' => 'myname',
'type' => 'type',
'year' => 'year',
'datetime' => 'datetime',
'deleted' => 'deleted',
'text' => 'text',
);
}
}

0 comments on commit a1e2ed7

Please sign in to comment.