From 6add43a4bc250305442d3615bec5e56dde8cb11c Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 11 May 2010 22:40:56 -0400 Subject: [PATCH] Fixing issue where id = null could cause SQL errors when saving more than one record with a null id. Fixes #675 --- cake/libs/model/model.php | 2 +- cake/tests/cases/libs/model/model_write.test.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 6b759ee66..4efe17e11 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1281,7 +1281,7 @@ class Model extends Overloadable { } } - 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(); diff --git a/cake/tests/cases/libs/model/model_write.test.php b/cake/tests/cases/libs/model/model_write.test.php index b30a8f25c..d405d413e 100644 --- a/cake/tests/cases/libs/model/model_write.test.php +++ b/cake/tests/cases/libs/model/model_write.test.php @@ -905,13 +905,14 @@ class ModelWriteTest extends BaseModelTest { * @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);