Fixing issue where id = null could cause SQL errors when saving more than one record with a null id. Fixes #675

This commit is contained in:
Mark Story 2010-05-11 22:40:56 -04:00
parent 3539660cd0
commit 6add43a4bc
2 changed files with 3 additions and 2 deletions

View file

@ -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();

View file

@ -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);