Refactoring model constructor

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6678 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-04-17 13:10:27 +00:00
parent d64e94e264
commit 8f3a2c6022
2 changed files with 13 additions and 11 deletions

View file

@ -360,17 +360,7 @@ class Model extends Overloadable {
$this->__createLinks(); $this->__createLinks();
if ($this->displayField == null) { if ($this->displayField == null) {
if ($this->hasField('title')) { $this->displayField = $this->hasField(array('title', 'name', $this->primaryKey));
$this->displayField = 'title';
}
if ($this->hasField('name')) {
$this->displayField = 'name';
}
if ($this->displayField == null) {
$this->displayField = $this->primaryKey;
}
} }
} }

View file

@ -377,6 +377,7 @@ class ModelTest extends CakeTestCase {
function testFindSelfAssociations() { function testFindSelfAssociations() {
$this->loadFixtures('Person'); $this->loadFixtures('Person');
$this->model =& new Person(); $this->model =& new Person();
$this->model->recursive = 2; $this->model->recursive = 2;
$result = $this->model->read(null, 1); $result = $this->model->read(null, 1);
@ -3422,6 +3423,17 @@ class ModelTest extends CakeTestCase {
} }
} }
function testDisplayField() {
$this->loadFixtures('Post', 'Comment', 'Person');
$this->Post = new Post();
$this->Comment = new Comment();
$this->Person = new Person();
$this->assertEqual($this->Post->displayField, 'title');
$this->assertEqual($this->Person->displayField, 'name');
$this->assertEqual($this->Comment->displayField, 'id');
}
function endTest() { function endTest() {
ClassRegistry::flush(); ClassRegistry::flush();
} }