Fixes #3411, failing test when $data has more than one models data.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5789 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-10-19 03:33:19 +00:00
parent cc7d1ab74c
commit 34380bf243
2 changed files with 22 additions and 13 deletions

View file

@ -824,10 +824,13 @@ class Model extends Overloadable {
if (isset($this->validationErrors[$x])) {
unset ($this->validationErrors[$x]);
}
if ($x === $this->primaryKey) {
$this->id = $y;
if ($n == $this->name || is_array($y)) {
if ($x === $this->primaryKey) {
$this->id = $y;
}
$this->data[$n][$x] = $y;
}
$this->data[$n][$x] = $y;
}
}
}

View file

@ -999,23 +999,29 @@ class ModelTest extends CakeTestCase {
$this->assertEqual($result, 4);
}
function testUpdateExisting() {
$this->model =& new User();
$model_id = 1000;
$this->model->id = $model_id;
$this->model->id = $id = 1000;
$this->model->delete();
$this->model->save( array('User'=>array('id'=>$model_id, 'user'=>'some user')) );
$this->assertEqual($this->model->id, $model_id);
$this->model->save(array('User' => array('id' => $id, 'user' => 'some user')));
$this->assertEqual($this->model->id, $id);
$this->model->save( array('User'=>array('user'=>'updated user')) );
$this->assertEqual($this->model->id, $model_id);
$this->model->save(array('User' => array('user' => 'updated user')));
$this->assertEqual($this->model->id, $id);
$this->Article =& new Article();
$this->Comment =& new Comment();
$data = array('Comment' => array('id' => 1, 'comment' => 'First Comment for First Article'),
'Article' => array('id' => 2, 'title' => 'Second Article'));
$result = $this->Article->save($data);
$this->assertTrue($result);
$result = $this->Comment->save($data);
$this->assertTrue($result);
}
function testBindUnbind() {
$this->model =& new User();