Skip to content

Commit

Permalink
Merge pull request phalcon#11983 from rudiservo/Issue-10800
Browse files Browse the repository at this point in the history
Proposed Fix for Issue phalcon#10800
  • Loading branch information
andresgutierrez authored Jul 18, 2016
2 parents ff20a9e + 9cb6c83 commit e0dbeed
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions phalcon/mvc/model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -4246,6 +4246,12 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
let relation = <RelationInterface> manager->getRelationByAlias(modelName, lowerProperty);
if typeof relation == "object" {

/*
Not fetch a relation if it is on CamelCase
*/
if isset this->{lowerProperty} && typeof this->{lowerProperty} == "object" {
return this->{lowerProperty};
}
/**
* Get the related records
*/
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/Mvc/ModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Phalcon\Test\Unit\Mvc;

use Phalcon\Mvc\Model\Criteria;
use Phalcon\Test\Models\AlbumORama\Albums;
use Phalcon\Test\Module\UnitTest;

/**
* \Phalcon\Test\Unit\Mvc\Model\ManagerTest
* Tests the Phalcon\Mvc\Model\Manager component
*
* @copyright (c) 2011-2016 Phalcon Team
* @link http://www.phalconphp.com
* @author Andres Gutierrez <andres@phalconphp.com>
* @author Serghei Iakovlev <serghei@phalconphp.com>
* @author Wojciech Ślawski <jurigag@gmail.com>
* @package Phalcon\Test\Unit\Mvc\Model
*
* The contents of this file are subject to the New BSD License that is
* bundled with this package in the file docs/LICENSE.txt
*
* If you did not receive a copy of the license and are unable to obtain it
* through the world-wide-web, please send an email to license@phalconphp.com
* so that we can send you a copy immediately.
*/
class ModelTest extends UnitTest
{
/**
* @var Manager
*/
private $modelsManager;


protected function _before()
{
parent::_before();
/** @var \Phalcon\Mvc\Application $app */
$app = $this->tester->getApplication();
$this->modelsManager = $app->getDI()->getShared('modelsManager');
}

public function testCamelCaseRelation()
{
$this->specify(
"CamelCase relation calls should be the same cache",
function () {
$this->modelsManager->registerNamespaceAlias('AlbumORama','Phalcon\Test\Models\AlbumORama');
$album = Albums::findFirst();
$album->artist->name = 'NotArtist';
expect($album->artist->name)->equals($album->Artist->name);
}
);
}
}

0 comments on commit e0dbeed

Please sign in to comment.