Skip to content

Commit

Permalink
Fixing issue where id = null could cause SQL errors when saving more …
Browse files Browse the repository at this point in the history
…than one record with a null id. Fixes #675
  • Loading branch information
markstory committed May 12, 2010
1 parent 3539660 commit 6add43a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cake/libs/model/model.php
Expand Up @@ -1281,7 +1281,7 @@ function save($data = null, $validate = true, $fieldList = array()) {
}
}

if (isset($this->data[$this->alias][$this->primaryKey]) && empty($this->data[$this->alias][$this->primaryKey])) {
if (empty($this->data[$this->alias][$this->primaryKey])) {
unset($this->data[$this->alias][$this->primaryKey]);
}
$fields = $values = array();
Expand Down
3 changes: 2 additions & 1 deletion cake/tests/cases/libs/model/model_write.test.php
Expand Up @@ -905,13 +905,14 @@ function testSaveWithCreate() {
* @return void
*/
function testSaveWithNullId() {
$this->loadFixtures('User');
$User =& new User();
$User->read(null, 1);
$User->data['User']['id'] = null;
$this->assertTrue($User->save(array('password' => 'test')));
$this->assertTrue($User->id > 0);

$User->read(null, 2);
$result = $User->read(null, 2);
$User->data['User']['id'] = null;
$this->assertTrue($User->save(array('password' => 'test')));
$this->assertTrue($User->id > 0);
Expand Down

0 comments on commit 6add43a

Please sign in to comment.