Skip to content

Commit

Permalink
fixes #6293, Deleting non-existing record causes save() to fail. Than…
Browse files Browse the repository at this point in the history
…ks 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
  • Loading branch information
gwoo committed Apr 22, 2009
1 parent 0cc3d51 commit fd0c39f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cake/libs/model/model.php
Expand Up @@ -1853,7 +1853,7 @@ function exists($reset = false) {
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());
Expand Down
42 changes: 36 additions & 6 deletions cake/tests/cases/libs/model/model.test.php
Expand Up @@ -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'
);
/**
Expand Down Expand Up @@ -3921,15 +3921,15 @@ function testCounterCacheUpdated() {
$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
* @return void
*/
function testCounterCacheWithNonstandardPrimaryKey() {
$this->loadFixtures(
'CounterCacheUserNonstandardPrimaryKey',
'CounterCacheUserNonstandardPrimaryKey',
'CounterCachePostNonstandardPrimaryKey'
);

Expand Down Expand Up @@ -4027,6 +4027,36 @@ function testDel() {
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
Expand Down

0 comments on commit fd0c39f

Please sign in to comment.