From 46df1be3844286dd875dff91e47c9fa345619ab0 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 25 Apr 2010 02:34:18 +0530 Subject: [PATCH] Model::deleteAll() now returns false if the 'find' to fetch records ids returns false (in case of sql error). Closes #272 --- cake/libs/model/model.php | 13 +++++++------ cake/tests/cases/libs/model/model_delete.test.php | 6 ++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index f017c7bc5..8bf362710 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1907,14 +1907,15 @@ class Model extends Overloadable { 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; } diff --git a/cake/tests/cases/libs/model/model_delete.test.php b/cake/tests/cases/libs/model/model_delete.test.php index 68088b42c..1cc81cd77 100644 --- a/cake/tests/cases/libs/model/model_delete.test.php +++ b/cake/tests/cases/libs/model/model_delete.test.php @@ -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'); } /**