Permalink
Browse files

Fixing issue where id = null could cause SQL errors when saving more …

…than one record with a null id. Fixes #675
  • Loading branch information...
1 parent 3539660 commit 6add43a4bc250305442d3615bec5e56dde8cb11c @markstory markstory committed May 12, 2010
Showing with 3 additions and 2 deletions.
  1. +1 −1 cake/libs/model/model.php
  2. +2 −1 cake/tests/cases/libs/model/model_write.test.php
@@ -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();
@@ -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);

0 comments on commit 6add43a

Please sign in to comment.