mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
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:
parent
994cfd3c89
commit
282bfbf4fc
2 changed files with 23 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue