diff --git a/phalcon/mvc/model.zep b/phalcon/mvc/model.zep index a06eec99c51..f8f2af3cadd 100644 --- a/phalcon/mvc/model.zep +++ b/phalcon/mvc/model.zep @@ -4246,6 +4246,12 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface let relation = 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 */ diff --git a/tests/unit/Mvc/ModelTest.php b/tests/unit/Mvc/ModelTest.php new file mode 100644 index 00000000000..dec3bea1ea1 --- /dev/null +++ b/tests/unit/Mvc/ModelTest.php @@ -0,0 +1,55 @@ + + * @author Serghei Iakovlev + * @author Wojciech Ĺšlawski + * @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); + } + ); + } +}