mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Model::deleteAll() now returns false if the 'find' to fetch records ids returns false (in case of sql error). Closes #272
This commit is contained in:
parent
a691edbcff
commit
4efb07b15a
2 changed files with 13 additions and 6 deletions
|
@ -1885,14 +1885,15 @@ class Model extends Object {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -423,6 +423,12 @@ class ModelDeleteTest extends BaseModelTest {
|
|||
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue