Fixing SQL expression handling in Model::field() (TIcket #2283)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4684 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-03-26 18:38:54 +00:00
parent 994cfd3c89
commit 282bfbf4fc
2 changed files with 23 additions and 6 deletions

View file

@ -957,18 +957,17 @@ class Model extends Overloadable {
if (strpos($name, '.') === false) {
if (isset($data[$this->name][$name])) {
return $data[$this->name][$name];
} else {
return false;
}
} else {
$name = explode('.', $name);
if (isset($data[$name[0]][$name[1]])) {
return $data[$name[0]][$name[1]];
} else {
return false;
}
}
if (isset($data[0]) && count($data[0]) > 0) {
$name = key($data[0]);
return $data[0][$name];
}
} else {
return false;
}

View file

@ -254,7 +254,25 @@ class ModelTest extends CakeTestCase {
$expected = array();
$this->assertEqual($result, $expected);
}
function testFindField() {
$this->model =& new User();
$this->model->id = 1;
$result = $this->model->field('user');
$this->assertEqual($result, 'mariano');
$result = $this->model->field('User.user');
$this->assertEqual($result, 'mariano');
$this->model->id = false;
$result = $this->model->field('user', array('user' => 'mariano'));
$this->assertEqual($result, 'mariano');
$result = $this->model->field('COUNT(*) AS count', true);
$this->assertEqual($result, 4);
}
function testBindUnbind() {
$this->model =& new User();