Skip to content

Commit

Permalink
Don't overwrite properties when they are set.
Browse files Browse the repository at this point in the history
If modelClass or modelKey is set the framework should not overwrite
them.
  • Loading branch information
markstory committed Dec 7, 2013
1 parent 5a58c8c commit 14a6e01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Cake/Test/TestCase/Controller/ControllerTest.php
Expand Up @@ -533,7 +533,11 @@ public function testMergeVars() {
$TestController = new AnotherTestController($request);
$TestController->constructClasses();

$this->assertEquals('AnotherTest', $TestController->modelClass);
$this->assertEquals(
'Post',
$TestController->modelClass,
'modelClass should not be overwritten when defined.'
);
}

/**
Expand Down
13 changes: 10 additions & 3 deletions Cake/Utility/RepositoryAwareTrait.php
Expand Up @@ -48,11 +48,18 @@ trait RepositoryAwareTrait {
/**
* Set the modelClass and modelKey properties based on conventions.
*
* If the properties are already set they w
* If the properties are already set they will not be overwritten
*
* @param string $name
* @return void
*/
protected function _setModelClass($name) {
$this->modelClass = Inflector::singularize($this->name);
$this->modelKey = Inflector::underscore($this->modelClass);
if (empty($this->modelClass)) {
$this->modelClass = Inflector::singularize($this->name);
}
if (empty($this->modelKey)) {
$this->modelKey = Inflector::underscore($this->modelClass);
}
}
/**
* Loads and constructs repository objects required by this object
Expand Down

0 comments on commit 14a6e01

Please sign in to comment.