Correcting issue in Model::__save() to prevent overwriting of existing record data

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6700 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-04-19 13:30:11 +00:00
parent f34ae31184
commit 16bfee9831
2 changed files with 4 additions and 4 deletions

View file

@ -1426,7 +1426,7 @@ class Model extends Overloadable {
if (!($model->create($data) && $this->validates())) { if (!($model->create($data) && $this->validates())) {
return false; return false;
} }
} elseif (!($model->create($data) && $model->save(null, $options))) { } elseif (!($model->create(null) !== null && $model->save($data, $options))) {
return false; return false;
} }
return true; return true;

View file

@ -2150,16 +2150,16 @@ class ModelTest extends CakeTestCase {
); );
$ts = date('Y-m-d H:i:s'); $ts = date('Y-m-d H:i:s');
$this->assertTrue($this->model->saveAll($data)); $this->assertTrue($this->model->saveAll($data));
$result = $this->model->find('all', array('recursive' => -1)); $result = $this->model->find('all', array('recursive' => -1));
$expected = array( $expected = array(
array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N', 'created' => '2007-03-18 10:39:23', 'updated' => $ts)), array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N', 'created' => '2007-03-18 10:39:23', 'updated' => $ts)),
array('Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Just update the title', 'body' => 'Second Post Body', 'published' => 'N', 'created' => '2007-03-18 10:41:23', 'updated' => $ts)), array('Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Just update the title', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => $ts)),
array('Post' => array('id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')), array('Post' => array('id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')),
array('Post' => array('id' => '4', 'author_id' => '2', 'title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'published' => 'N', 'created' => $ts, 'updated' => $ts)) array('Post' => array('id' => '4', 'author_id' => '2', 'title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'published' => 'N', 'created' => $ts, 'updated' => $ts))
); );
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->model->validate = array('title' => VALID_NOT_EMPTY, 'author_id' => 'numeric'); $this->model->validate = array('title' => VALID_NOT_EMPTY, 'author_id' => 'numeric');
$data = array( $data = array(
array('id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y'), array('id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y'),