fixes #5331, model alias no longer overwritten

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7515 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-08-27 01:30:09 +00:00
parent 7e039ee62d
commit 7fe1a03fda
2 changed files with 50 additions and 5 deletions

View file

@ -318,16 +318,22 @@ class Model extends Overloadable {
extract(array_merge(
array('id' => $this->id, 'table' => $this->useTable, 'ds' => $this->useDbConfig, 'name' => $this->name, 'alias' => $this->alias),
$id));
$this->name = $name;
$this->alias = $alias;
}
if ($this->name === null) {
$this->name = get_class($this);
if (isset($name)) {
$this->name = $name;
} else {
$this->name = get_class($this);
}
}
if ($this->alias === null) {
$this->alias = $this->name;
if (isset($alias)) {
$this->alias = $alias;
} else {
$this->alias = $this->name;
}
}
if ($this->primaryKey === null) {

View file

@ -127,6 +127,33 @@ class ControllerComment extends CakeTestModel {
*/
var $alias = 'ControllerComment';
}
/**
* NameTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.controller
*/
class NameTest extends CakeTestModel {
/**
* name property
* @var string 'Name'
* @access public
*/
var $name = 'Name';
/**
* useTable property
* @var string 'names'
* @access public
*/
var $useTable = 'comments';
/**
* alias property
*
* @var string 'ControllerComment'
* @access public
*/
var $alias = 'Name';
}
if (!class_exists('AppController')) {
/**
* AppController class
@ -231,7 +258,7 @@ class ControllerTest extends CakeTestCase {
* @var array
* @access public
*/
var $fixtures = array('core.post', 'core.comment');
var $fixtures = array('core.post', 'core.comment', 'core.name');
/**
* testConstructClasses method
*
@ -258,6 +285,18 @@ class ControllerTest extends CakeTestCase {
unset($Controller);
}
function testAliasName() {
$Controller =& new Controller();
$Controller->uses = array('NameTest');
$Controller->constructClasses();
$this->assertEqual($Controller->NameTest->name, 'Name');
$this->assertEqual($Controller->NameTest->alias, 'Name');
unset($Controller);
}
/**
* testPersistent method
*