mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
3539660cd0
commit
6add43a4bc
2 changed files with 3 additions and 2 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue