fixes #6293, Deleting non-existing record causes save() to fail. Thanks to msadouni for the patch and test!

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8150 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2009-04-22 16:47:34 +00:00
parent 0cc3d5149f
commit fd0c39fcc6
2 changed files with 37 additions and 7 deletions

View file

@ -1853,7 +1853,7 @@ class Model extends Overloadable {
if ($this->getID() === false || $this->useTable === false) {
return false;
}
if ($this->__exists !== null && $reset !== true) {
if (!empty($this->__exists) && $reset !== true) {
return $this->__exists;
}
$conditions = array($this->alias . '.' . $this->primaryKey => $this->getID());

View file

@ -63,10 +63,10 @@ class ModelTest extends CakeTestCase {
'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.basket',
'core.overall_favorite', 'core.account', 'core.content', 'core.content_account',
'core.film_file', 'core.test_plugin_article', 'core.test_plugin_comment', 'core.uuiditem',
'core.counter_cache_user', 'core.counter_cache_post',
'core.counter_cache_user_nonstandard_primary_key',
'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio',
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit',
'core.counter_cache_user', 'core.counter_cache_post',
'core.counter_cache_user_nonstandard_primary_key',
'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio',
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit',
'core.fruits_uuid_tag', 'core.uuid_tag'
);
/**
@ -3921,7 +3921,7 @@ class ModelTest extends CakeTestCase {
$this->assertEqual($users[1]['User']['post_count'], 2);
}
/**
* Test counter cache with models that use a non-standard (i.e. not using 'id')
* Test counter cache with models that use a non-standard (i.e. not using 'id')
* as their primary key.
*
* @access public
@ -3929,7 +3929,7 @@ class ModelTest extends CakeTestCase {
*/
function testCounterCacheWithNonstandardPrimaryKey() {
$this->loadFixtures(
'CounterCacheUserNonstandardPrimaryKey',
'CounterCacheUserNonstandardPrimaryKey',
'CounterCachePostNonstandardPrimaryKey'
);
@ -4027,6 +4027,36 @@ class ModelTest extends CakeTestCase {
array('Article' => array('id' => 1, 'title' => 'First Article' ))
);
$this->assertEqual($result, $expected);
// make sure deleting a non-existent record doesn't break save()
// ticket #6293
$this->loadFixtures('Uuid');
$Uuid =& new Uuid();
$data = array(
'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3',
'52C8865C-10EE-4302-AE6C-6E7D8E12E2C8',
'8208C7FE-E89C-47C5-B378-DED6C271F9B8');
foreach ($data as $id) {
$Uuid->save(array('id' => $id));
}
$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
foreach ($data as $id) {
$Uuid->save(array('id' => $id));
}
$result = $Uuid->find('all', array(
'conditions' => array('id' => $data),
'fields' => array('id'),
'order' => 'id'));
$expected = array(
array('Uuid' => array(
'id' => '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8')),
array('Uuid' => array(
'id' => '8208C7FE-E89C-47C5-B378-DED6C271F9B8')),
array('Uuid' => array(
'id' => 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3')));
$this->assertEqual($result, $expected);
}
/**
* testDeleteAll method