Skip to content

Commit

Permalink
Model::deleteAll() now returns false if the 'find' to fetch records i…
Browse files Browse the repository at this point in the history
…ds returns false (in case of sql error). Closes #272
  • Loading branch information
ADmad committed Apr 24, 2010
1 parent 3e85577 commit 46df1be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cake/libs/model/model.php
Expand Up @@ -1907,14 +1907,15 @@ function deleteAll($conditions, $cascade = true, $callbacks = false) {
if (!$cascade && !$callbacks) {
return $db->delete($this, $conditions);
} else {
$ids = Set::extract(
$this->find('all', array_merge(array(
'fields' => "{$this->alias}.{$this->primaryKey}",
'recursive' => 0), compact('conditions'))
),
"{n}.{$this->alias}.{$this->primaryKey}"
$ids = $this->find('all', array_merge(array(
'fields' => "{$this->alias}.{$this->primaryKey}",
'recursive' => 0), compact('conditions'))
);
if ($ids === false) {
return false;
}

$ids = Set::extract($ids, "{n}.{$this->alias}.{$this->primaryKey}");
if (empty($ids)) {
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions cake/tests/cases/libs/model/model_delete.test.php
Expand Up @@ -423,6 +423,12 @@ function testDeleteAll() {

$result = $TestModel->deleteAll(array('Article.user_id' => 999));
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');

$this->expectError();
ob_start();
$result = $TestModel->deleteAll(array('Article.non_existent_field' => 999));
ob_get_clean();
$this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s');
}

/**
Expand Down

0 comments on commit 46df1be

Please sign in to comment.